package com.ybkj.daijia.server.service.impl;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ybkj.daijia.ServiceSetting;
import com.ybkj.daijia.serverUtils.ServiceUtil;
import com.ybkj.daijia.Setting;
import com.ybkj.daijia.serverUtils.SettingUtils;
import com.ybkj.daijia.chart.HourChart;
import com.ybkj.daijia.chart.TableOrderMonthVo;
import com.ybkj.daijia.common.CompanyOrderVo;
import com.ybkj.daijia.common.DirverStatistics;
import com.ybkj.daijia.common.DriverOrderDetailVo;
import com.ybkj.daijia.common.DriverOrderVo;
import com.ybkj.daijia.common.InfoFeeVo;
import com.ybkj.daijia.common.MemberOrderVo;
import com.ybkj.daijia.common.OrderFromSourceVo;
import com.ybkj.daijia.common.OrderTypeVo;
import com.ybkj.daijia.common.PageVo;
import com.ybkj.daijia.common.Pager;
import com.ybkj.daijia.common.Principal;
import com.ybkj.daijia.common.UserTypeVo;
import com.ybkj.daijia.config.ErrandApi;
import com.ybkj.daijia.config.FreightApi;
import com.ybkj.daijia.config.PassengerApi;
import com.ybkj.daijia.config.ZhuanApi;
import com.ybkj.daijia.config.ZhuanxianApi;
import com.ybkj.daijia.server.mapper.ChartDayMapper;
import com.ybkj.daijia.server.mapper.ChartMonthMapper;
import com.ybkj.daijia.server.mapper.ChartYearMapper;
import com.ybkj.daijia.server.mapper.CompanyMapper;
import com.ybkj.daijia.server.mapper.DriverMapper;
import com.ybkj.daijia.server.mapper.DriverPaymentsRecordMapper;
import com.ybkj.daijia.server.mapper.MemberMapper;
import com.ybkj.daijia.server.mapper.OrderFinishedInfoMapper;
import com.ybkj.daijia.server.mapper.OrderMapper;
import com.ybkj.daijia.server.mc.Passenger;
import com.ybkj.daijia.server.model.ChartDay;
import com.ybkj.daijia.server.model.ChartMonth;
import com.ybkj.daijia.server.model.ChartYear;
import com.ybkj.daijia.server.model.Company;
import com.ybkj.daijia.server.model.Driver;
import com.ybkj.daijia.server.model.DriverPaymentsRecord;
import com.ybkj.daijia.server.model.Order;
import com.ybkj.daijia.server.sales.Activity;
import com.ybkj.daijia.server.service.ChartYearService;
import com.ybkj.daijia.server.service.ErrandService;
import com.ybkj.daijia.server.service.FreightService;
import com.ybkj.daijia.server.service.ZhuancheService;
import com.ybkj.daijia.server.service.ZhuanxianService;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;

@Service
public class DefaultChartYearService implements ChartYearService {

    private static final Logger logger = LoggerFactory.getLogger(DefaultChartYearService.class);

    @Autowired
    private SettingUtils settingUtils;

    @Autowired
    private ChartDayMapper chartDayMapper;

    @Autowired
    private ChartMonthMapper chartMonthMapper;

    @Autowired
    private ChartYearMapper chartYearMapper;

    @Autowired
    private CompanyMapper companyMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private DriverMapper driverMapper;

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private OrderFinishedInfoMapper orderFinishedInfoMapper;

    @Autowired
    private DriverPaymentsRecordMapper driverPaymentsRecordMapper;

    @Autowired
    private PassengerApi passengerApi;

    @Autowired
    private ErrandApi errandApi;

    @Autowired
    private ZhuanApi zhuanApi;

    @Autowired
    private FreightApi freightApi;

    @Autowired
    private ZhuanxianApi zhuanxianApi;

    @Autowired
    private ErrandService errandService;

    @Autowired
    private ZhuancheService zhuancheService;

    @Autowired
    private ZhuanxianService zhuanxianService;

    @Autowired
    private FreightService freightService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addDayRecord(Order order) {

        Company company = companyMapper.selectByPrimaryKey(order.getCompanyId());

        if (null != company) {
            Calendar calendar = Calendar.getInstance();
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int hour = calendar.get(Calendar.HOUR_OF_DAY);

            if (Order.ORDER_STATUS_FINISHED == order.getStatus()
                || Order.ORDER_STATUS_BAODAN == order.getStatus()) {

                // 增加年记录
                ChartYear chartYear = chartYearMapper.selectByYearAndCompany(year, company.getId());

                if (null == chartYear) {
                    chartYear = new ChartYear();
                    chartYear.setYear(year);
                    chartYear.setCompanyId(company.getId());
                    chartYear.setCompanyName(company.getAbbreviation());
                    chartYear.setTotalSuccessNum(1);
                    chartYear.setTotalPrice(order.getRealCash());
                    chartYearMapper.insertRecord(chartYear);
                } else {
                    chartYear.setTotalSuccessNum(chartYear.getTotalSuccessNum() + 1);
                    chartYear.setTotalPrice(chartYear.getTotalPrice().add(order.getRealCash()));
                    chartYearMapper.updateByPrimaryKey(chartYear);
                }

                // 增加月记录
                ChartMonth chartMonth = chartMonthMapper
                    .selectByYearAndMonth(chartYear.getId(), month);
                if (null == chartMonth) {
                    chartMonth = new ChartMonth();
                    chartMonth.setMonth(month);
                    chartMonth.setYearId(chartYear.getId());
                    chartMonth.setTotalSuccessNum(1);
                    chartMonth.setTotalPrice(order.getRealCash());
                } else {
                    chartMonth.setTotalSuccessNum(chartMonth
                        .getTotalSuccessNum() + 1);
                    chartMonth.setTotalPrice(chartMonth.getTotalPrice().add(
                        order.getRealCash()));
                }

                if (null == chartMonth.getId()) {
                    chartMonthMapper.insertRecord(chartMonth);
                } else {
                    chartMonthMapper.updateByPrimaryKey(chartMonth);
                }

                // 增加日记录
                ChartDay chartDay = chartDayMapper.selectByMonthAndDay(chartMonth.getId(), day);

                if (null == chartDay) {
                    chartDay = new ChartDay();
                    chartDay.setMonthId(chartMonth.getId());
                    chartDay.setDay(day);
                    chartDay.setTotalSuccessNum(1);
                    chartDay.setTotalPrice(order.getRealCash());
                } else {
                    chartDay.setTotalSuccessNum(chartDay.getTotalSuccessNum() + 1);
                    chartDay.setTotalPrice(chartDay.getTotalPrice().add(
                        order.getRealCash()));
                }

                try {
                    Class<ChartDay> clazz = ChartDay.class;

                    Method getMethod = ReflectionUtils
                        .findMethod(clazz, "getHour" + hour + "SuccessNum");
                    Method setMethod = ReflectionUtils
                        .findMethod(clazz, "setHour" + hour + "SuccessNum", long.class);

                    long num = (Long) ReflectionUtils.invokeMethod(getMethod, chartDay);
                    ReflectionUtils.invokeMethod(setMethod, chartDay, num + 1);

                    getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour + "TotalPrice");
                    setMethod = ReflectionUtils
                        .findMethod(clazz, "setHour" + hour + "TotalPrice", BigDecimal.class);

                    BigDecimal price = (BigDecimal) ReflectionUtils
                        .invokeMethod(getMethod, chartDay);
                    ReflectionUtils
                        .invokeMethod(setMethod, chartDay, price.add(order.getRealCash()));

                } catch (SecurityException e) {
                    e.printStackTrace();
                }

                if (null == chartDay.getId()) {
                    chartDayMapper.insertRecord(chartDay);
                } else {
                    chartDayMapper.updateByPrimaryKey(chartDay);
                }

            } else if (Order.ORDER_STATUS_CANCELED == order.getStatus()) {

                // 增加年记录
                ChartYear chartYear = chartYearMapper.selectByYearAndCompany(year, company.getId());

                if (null == chartYear) {
                    chartYear = new ChartYear();
                    chartYear.setYear(year);
                    chartYear.setCompanyId(company.getId());
                    chartYear.setCompanyName(company.getAbbreviation());
                    chartYear.setTotalCancelNum(1);
                    chartYearMapper.insertRecord(chartYear);
                } else {
                    chartYear.setTotalCancelNum(chartYear.getTotalCancelNum() + 1);
                    chartYearMapper.updateByPrimaryKey(chartYear);
                }

                // 增加月记录
                ChartMonth chartMonth = chartMonthMapper
                    .selectByYearAndMonth(chartYear.getId(), month);

                if (null == chartMonth) {
                    chartMonth = new ChartMonth();
                    chartMonth.setMonth(month);
                    chartMonth.setYearId(chartYear.getId());
                    chartMonth.setTotalCancelNum(1);
                    chartMonthMapper.insertRecord(chartMonth);
                } else {
                    chartMonth.setTotalCancelNum(chartMonth.getTotalCancelNum() + 1);
                    chartMonthMapper.updateByPrimaryKey(chartMonth);
                }

                // 增加日记录
                ChartDay chartDay = chartDayMapper.selectByMonthAndDay(chartMonth.getId(), day);

                if (null == chartDay) {
                    chartDay = new ChartDay();
                    chartDay.setMonthId(chartMonth.getId());
                    chartDay.setDay(day);
                    chartDay.setTotalCancelNum(1);
                } else {
                    chartDay.setTotalCancelNum(chartDay.getTotalCancelNum() + 1);
                }

                try {

                    Class<ChartDay> clazz = ChartDay.class;

                    Method getMethod = ReflectionUtils
                        .findMethod(clazz, "getHour" + hour + "CancelNum");
                    Method setMethod = ReflectionUtils
                        .findMethod(clazz, "setHour" + hour + "CancelNum", long.class);

                    long num = (Long) ReflectionUtils.invokeMethod(getMethod, chartDay);
                    ReflectionUtils.invokeMethod(setMethod, chartDay, num + 1);

                } catch (SecurityException e) {
                    e.printStackTrace();
                }

                if (null == chartDay.getId()) {
                    chartDayMapper.insertRecord(chartDay);
                } else {
                    chartDayMapper.updateByPrimaryKey(chartDay);
                }

            } else {
                logger.warn(
                    "order: {}'s status is not finished or canceled, it can not be add to day record",
                    order.getOrderNumber());
            }
        } else {
            logger.warn(
                "order: {} has no company, it can not be add to day record",
                order.getOrderNumber());
        }
    }

    @Override
    public ChartYear dataForYear(int year, Long companyId) {
        ChartYear chartYear = new ChartYear();
        if (companyId != null) {
            chartYear = chartYearMapper.selectByYearAndCompany(year, companyId);
            if (null == chartYear) {
                chartYear = new ChartYear();
                return chartYear;
            }

            List<ChartMonth> months = new LinkedList<ChartMonth>();

            for (int i = 0; i < 12; i++) {
                ChartMonth month = this.findByYearAndMonth(chartYear, i);
                months.add(month);
            }

            chartYear.setMonths(months);

            return chartYear;

        } else {

            List<ChartYear> list = chartYearMapper.selectAllByYear(year);
            long yearFinish = 0;
            long yearCancel = 0;
            BigDecimal yearMoeny = BigDecimal.ZERO;
            List<ChartMonth> months = new LinkedList<ChartMonth>();
            for (int i = 0; i < 12; i++) {
                ChartMonth yearMonth = new ChartMonth();
                List<ChartDay> days = new ArrayList<ChartDay>();
                yearMonth.setTotalPrice(BigDecimal.ZERO);
                yearMonth.setMonth(i);
                for (ChartYear chart : list) {
                    yearFinish += chart.getTotalSuccessNum();
                    yearCancel += chart.getTotalCancelNum();
                    yearMoeny = yearMoeny.add(chart.getTotalPrice());
                    ChartMonth month = this.findByYearAndMonth(chart, i);
                    yearMonth.setTotalCancelNum(
                        yearMonth.getTotalCancelNum() + month.getTotalCancelNum());
                    yearMonth.setTotalSuccessNum(
                        yearMonth.getTotalSuccessNum() + month.getTotalSuccessNum());
                    yearMonth.setTotalPrice(yearMonth.getTotalPrice().add(month.getTotalPrice()));
                }

                for (int j = 1; j <= yearMonth.getDays(); j++) {
                    ChartDay day = new ChartDay();
                    day.setDay(j);
                    for (ChartYear chart : list) {
                        ChartMonth month = this.findByYearAndMonth(chart, i);
                        List<ChartDay> list2 = month.getChartDays();
                        for (ChartDay tempDay : list2) {
                            if (j == tempDay.getDay()) {
                                day.setTotalCancelNum(
                                    day.getTotalCancelNum() + tempDay.getTotalCancelNum());
                                day.setTotalPrice(day.getTotalPrice().add(tempDay.getTotalPrice()));
                                day.setTotalSuccessNum(
                                    day.getTotalSuccessNum() + tempDay.getTotalSuccessNum());
                                break;
                            }
                        }
                    }
                    days.add(day);
                }

                yearMonth.setChartDays(days);
                months.add(yearMonth);

            }

            chartYear.setMonths(months);
            chartYear.setTotalCancelNum(yearCancel);
            chartYear.setTotalPrice(yearMoeny);
            chartYear.setTotalSuccessNum(yearFinish);
            return chartYear;

        }
    }

    @Override
    public ChartMonth findByYearAndMonth(ChartYear chartYear, Integer month) {

        ChartMonth chartMonth = chartMonthMapper.selectByYearAndMonth(chartYear.getId(), month);
        if (null == chartMonth) {
            chartMonth = new ChartMonth();
            chartMonth.setYearId(chartYear.getId());
            chartMonth.setMonth(month);
            chartMonth.setTotalCancelNum(0);
            chartMonth.setTotalSuccessNum(0);
            chartMonth.setTotalPrice(BigDecimal.ZERO);
            List<ChartDay> days = new ArrayList<ChartDay>(chartMonth.getDays());
            for (int k = 1; k <= chartMonth.getDays(); k++) {
                ChartDay day = new ChartDay();
                day.setDay(k);
                days.add(day);
            }
            chartMonth.setChartDays(days);
        } else {

            int maxDays = chartMonth.getDays();

            Setting setting = settingUtils.get();

            Class<ChartDay> clazz = ChartDay.class;

            List<ChartDay> days = new ArrayList<ChartDay>(maxDays);

            int totalCancel = 0;
            int totalSuccess = 0;
            BigDecimal totalJe = BigDecimal.ZERO;

            ChartDay today = null;

            for (int i = 1; i <= maxDays; i++) {

                long todayCancel = 0;
                long todaySuccess = 0;
                BigDecimal todayPrice = BigDecimal.ZERO;

                if (null == today) {
                    today = chartDayMapper.selectByMonthAndDay(chartMonth.getId(), i); // 查询当前日期
                }
                if (null != today) {
                    for (int hour = setting.getWorkBegin(); hour < 24; hour++) {

                        Method getMethod = ReflectionUtils.findMethod(clazz,
                            "getHour" + hour + "CancelNum");
                        todayCancel += (Long) ReflectionUtils.invokeMethod(
                            getMethod, today);

                        getMethod = ReflectionUtils.findMethod(clazz, "getHour"
                            + hour + "SuccessNum");
                        todaySuccess += (Long) ReflectionUtils.invokeMethod(
                            getMethod, today);

                        getMethod = ReflectionUtils.findMethod(clazz, "getHour"
                            + hour + "TotalPrice");
                        BigDecimal price = (BigDecimal) ReflectionUtils
                            .invokeMethod(getMethod, today);

                        todayPrice = todayPrice.add(price);
                    }
                } else {
                    today = new ChartDay();
                    today.setTotalCancelNum(todayCancel);
                    today.setTotalPrice(todayPrice);
                    today.setTotalSuccessNum(todaySuccess);
                    today.setDay(i);
                }

                ChartDay chartDay2 = getNextChartDay(chartYear.getYear(),
                    month, i, chartYear.getCompanyId()); // 查询第二天
                if (null != chartDay2) {

                    for (int hour = 0; hour < setting.getWorkBegin(); hour++) {

                        Method getMethod = ReflectionUtils.findMethod(clazz,
                            "getHour" + hour + "CancelNum");
                        todayCancel += (Long) ReflectionUtils.invokeMethod(
                            getMethod, chartDay2);

                        getMethod = ReflectionUtils.findMethod(clazz, "getHour"
                            + hour + "SuccessNum");
                        todaySuccess += (Long) ReflectionUtils.invokeMethod(
                            getMethod, chartDay2);

                        getMethod = ReflectionUtils.findMethod(clazz, "getHour"
                            + hour + "TotalPrice");
                        BigDecimal price = (BigDecimal) ReflectionUtils
                            .invokeMethod(getMethod, chartDay2);

                        todayPrice = todayPrice.add(price);
                    }
                }

                today.setTotalCancelNum(todayCancel);
                today.setTotalPrice(todayPrice);
                today.setTotalSuccessNum(todaySuccess);
                days.add(today);

                totalCancel += todayCancel;
                totalSuccess += todaySuccess;
                totalJe = totalJe.add(todayPrice);

                today = chartDay2;
            }

            chartMonth.setTotalCancelNum(totalCancel);
            chartMonth.setTotalSuccessNum(totalSuccess);
            chartMonth.setTotalPrice(totalJe);
            chartMonth.setChartDays(days);

        }

        return chartMonth;
    }

    @Override
    public ChartDay findByMonthAndDay(ChartMonth chartMonth, int day) {

        return chartDayMapper.selectByMonthAndDay(chartMonth.getId(), day);
    }

    @Override
    public ChartYear findByYearAndCompany(int year, Long companyId) {

        return chartYearMapper.selectByYearAndCompany(year, companyId);
    }

    @Override
    public ChartDay dataForDay(Integer year, Integer month, Integer day,
        Long companyID) {
        if (companyID != null) {
            Setting setting = settingUtils.get();

            ChartYear chartYear = chartYearMapper.selectByYearAndCompany(year, companyID);

            ChartMonth chartMonth = chartMonthMapper.selectByYearAndMonth(chartYear.getId(), month);

            ChartDay chartDay = chartDayMapper.selectByMonthAndDay(chartMonth.getId(), day);

            ChartDay chartDay2 = getNextChartDay(year, month, day, companyID);

            Class<ChartDay> clazz = ChartDay.class;

            int begin = setting.getWorkBegin();

            List<HourChart> hours = new LinkedList<HourChart>();

            for (int hour = begin; hour < 24; hour++) {

                HourChart hc = new HourChart();
                if (null != chartDay) {
                    Method getMethod = ReflectionUtils.findMethod(clazz, "getHour"
                        + hour + "CancelNum");
                    hc.setTotalCancel((Long) ReflectionUtils.invokeMethod(
                        getMethod, chartDay));

                    getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
                        + "SuccessNum");
                    hc.setTotalSuccess((Long) ReflectionUtils.invokeMethod(
                        getMethod, chartDay));

                    getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
                        + "TotalPrice");
                    hc.setTotalPrice((BigDecimal) ReflectionUtils.invokeMethod(
                        getMethod, chartDay));
                }
                hc.setHour(hour);

                hours.add(hc);
            }

            for (int hour = 0; hour < begin; hour++) {

                HourChart hc = new HourChart();
                if (null != chartDay2) {
                    Method getMethod = ReflectionUtils.findMethod(clazz, "getHour"
                        + hour + "CancelNum");
                    hc.setTotalCancel((Long) ReflectionUtils.invokeMethod(
                        getMethod, chartDay2));

                    getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
                        + "SuccessNum");
                    hc.setTotalSuccess((Long) ReflectionUtils.invokeMethod(
                        getMethod, chartDay2));

                    getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
                        + "TotalPrice");
                    hc.setTotalPrice((BigDecimal) ReflectionUtils.invokeMethod(
                        getMethod, chartDay2));
                }
                hc.setHour(hour);

                hours.add(hc);
            }

            chartDay.setHours(hours);

            return chartDay;
        } else {

            Setting setting = settingUtils.get();
            List<ChartYear> chartYear = chartYearMapper.selectAllByYear(year);
            ChartDay chartDay = new ChartDay();
            List<HourChart> hours = new LinkedList<HourChart>();
            Class<ChartDay> clazz = ChartDay.class;
            int begin = setting.getWorkBegin();
            for (int hour = begin; hour < 24; hour++) {
                HourChart hc = new HourChart();
                for (ChartYear chart : chartYear) {
                    ChartMonth chartMonth = chartMonthMapper
                        .selectByYearAndMonth(chart.getId(), month);
                    if (chartMonth != null) {
                        ChartDay chartDayTemp = chartDayMapper
                            .selectByMonthAndDay(chartMonth.getId(), day);

                        if (null != chartDayTemp) {
                            Method getMethod = ReflectionUtils.findMethod(clazz, "getHour"
                                + hour + "CancelNum");
                            hc.setTotalCancel((Long) ReflectionUtils.invokeMethod(
                                getMethod, chartDayTemp) + hc.getTotalCancel());

                            getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
                                + "SuccessNum");
                            hc.setTotalSuccess((Long) ReflectionUtils.invokeMethod(
                                getMethod, chartDayTemp) + hc.getTotalSuccess());

                            getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
                                + "TotalPrice");
                            hc.setTotalPrice(((BigDecimal) ReflectionUtils.invokeMethod(
                                getMethod, chartDayTemp)).add(hc.getTotalPrice()));
                        }
                        hc.setHour(hour);

                    }
                }
                hours.add(hc);
            }
            chartDay.setHours(hours);

            return chartDay;

 		/*ChartYear chartYear = chartYearMapper.selectByYearAndCompany(year,companyID);

 		ChartMonth chartMonth = chartMonthMapper.selectByYearAndMonth(chartYear.getId(),month);

 		ChartDay chartDay = chartDayMapper.selectByMonthAndDay(chartMonth.getId(), day);

 		ChartDay chartDay2 = getNextChartDay(year, month, day, companyID);

 		Class<ChartDay> clazz = ChartDay.class;

 		int begin = setting.getWorkBegin();

 		List<HourChart> hours = new LinkedList<HourChart>();

 		for (int hour = begin; hour < 24; hour++) {

 			HourChart hc = new HourChart();
 			if (null != chartDay) {
 				Method getMethod = ReflectionUtils.findMethod(clazz, "getHour"
 						+ hour + "CancelNum");
 				hc.setTotalCancel((Long) ReflectionUtils.invokeMethod(
 						getMethod, chartDay));

 				getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
 						+ "SuccessNum");
 				hc.setTotalSuccess((Long) ReflectionUtils.invokeMethod(
 						getMethod, chartDay));

 				getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
 						+ "TotalPrice");
 				hc.setTotalPrice((BigDecimal) ReflectionUtils.invokeMethod(
 						getMethod, chartDay));
 			}
 			hc.setHour(hour);

 			hours.add(hc);
 		}

 		for (int hour = 0; hour < begin; hour++) {

 			HourChart hc = new HourChart();
 			if (null != chartDay2) {
 				Method getMethod = ReflectionUtils.findMethod(clazz, "getHour"
 						+ hour + "CancelNum");
 				hc.setTotalCancel((Long) ReflectionUtils.invokeMethod(
 						getMethod, chartDay2));

 				getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
 						+ "SuccessNum");
 				hc.setTotalSuccess((Long) ReflectionUtils.invokeMethod(
 						getMethod, chartDay2));

 				getMethod = ReflectionUtils.findMethod(clazz, "getHour" + hour
 						+ "TotalPrice");
 				hc.setTotalPrice((BigDecimal) ReflectionUtils.invokeMethod(
 						getMethod, chartDay2));
 			}
 			hc.setHour(hour);

 			hours.add(hc);
 		}

 		chartDay.setHours(hours);

 		return chartDay;
    	 */

        }
    }

    private ChartDay getNextChartDay(Integer year, Integer month,
        Integer currentDay, Long companyID) {

        Calendar calender = Calendar.getInstance();
        calender.set(Calendar.YEAR, year);
        calender.set(Calendar.MONTH, month);
        calender.set(Calendar.DAY_OF_MONTH, currentDay);

        calender.setTime(DateUtils.addDays(calender.getTime(), 1));

        ChartYear chartYear = chartYearMapper
            .selectByYearAndCompany(calender.get(Calendar.YEAR), companyID);

        if (null != chartYear) {
            ChartMonth chartMonth = chartMonthMapper
                .selectByYearAndMonth(chartYear.getId(), calender.get(Calendar.MONTH));
            if (null != chartMonth) {
                ChartDay chartDay = chartDayMapper
                    .selectByMonthAndDay(chartMonth.getId(), calender.get(Calendar.DAY_OF_MONTH));

                return chartDay;
            }
        }

        return null;
    }

    @Override
    public List<CompanyOrderVo> companyOrder(Date start, Date end) {

        List<Company> companys = companyMapper.selectAll();

        List<CompanyOrderVo> volist = new ArrayList<CompanyOrderVo>();

        ServiceSetting serviceSetting = ServiceUtil.checkOpen();
        PageVo<CompanyOrderVo> result = null;
        PageVo<CompanyOrderVo> zhuanche = null;
        PageVo<CompanyOrderVo> freight = null;
        PageVo<CompanyOrderVo> zhuanxian = null;
        if (serviceSetting.isPaotui()) {
            result = errandService.companyOrder(start, end);
        }
        if (serviceSetting.isZhuanche()) {
            zhuanche = zhuancheService.companyOrder(start, end);
        }
        if (serviceSetting.isFreight()) {
            freight = freightService.companyOrder(start, end);
        }
        if (serviceSetting.isZhuanxian()) {
            zhuanxian = zhuanxianService.companyOrder(start, end);
        }
        CompanyOrderVo count = new CompanyOrderVo();
        CompanyOrderVo errandcount = new CompanyOrderVo();
        CompanyOrderVo zhuanchecount = new CompanyOrderVo();
        CompanyOrderVo freightcount = new CompanyOrderVo();
        CompanyOrderVo zhuanxiancount = new CompanyOrderVo();
        errandcount.setMoney(BigDecimal.ZERO);
        zhuanchecount.setMoney(BigDecimal.ZERO);
        zhuanxiancount.setMoney(BigDecimal.ZERO);
        count.setCompanyName("总计");
        count.setMoney(BigDecimal.ZERO);
        for (Company company : companys) {
            CompanyOrderVo cov = new CompanyOrderVo();
            cov.setCompanyName(company.getAbbreviation());
            long cancelNums = orderMapper
                .countByCompanyWithStatusAndDate(company.getId(), Order.ORDER_STATUS_CANCELED, null,
                    start, end);
            cov.setCancelNums(cancelNums);
            long finishNums = orderMapper
                .countFinishedByCompanyWithDate(company.getId(), start, end);
            cov.setFinishNums(finishNums);
            BigDecimal money = orderFinishedInfoMapper
                .sumAllRealCashByCompanyWithDate(company.getId(), start, end);
            cov.setMoney(money);
            count.setCancelNums(count.getCancelNums() + cancelNums);
            count.setFinishNums(count.getFinishNums() + finishNums);
            if (money != null) {
                count.setMoney(count.getMoney().add(money));
            }
            if (serviceSetting.isPaotui()) {
                for (CompanyOrderVo vo : result.getContent()) {
                    if (cov.getCompanyName().equals(vo.getCompanyName())) {
                        cov.setErrand(vo);
                        errandcount.setCancelNums(errandcount.getCancelNums() + vo.getCancelNums());
                        errandcount.setFinishNums(errandcount.getFinishNums() + vo.getFinishNums());
                        errandcount.setMoney(errandcount.getMoney().add(vo.getMoney()));
                        break;
                    }
                }
            }
            if (serviceSetting.isZhuanche()) {
                for (CompanyOrderVo vo : zhuanche.getContent()) {
                    if (cov.getCompanyName().equals(vo.getCompanyName())) {
                        cov.setZhuanche(vo);
                        zhuanchecount
                            .setCancelNums(zhuanchecount.getCancelNums() + vo.getCancelNums());
                        zhuanchecount
                            .setFinishNums(zhuanchecount.getFinishNums() + vo.getFinishNums());
                        zhuanchecount.setMoney(zhuanchecount.getMoney().add(vo.getMoney()));
                        break;
                    }
                }
            }
            if (serviceSetting.isZhuanxian()) {
                for (CompanyOrderVo vo : zhuanxian.getContent()) {
                    if (cov.getCompanyName().equals(vo.getCompanyName())) {
                        cov.setZhuanxian(vo);
                        zhuanxiancount
                            .setCancelNums(zhuanxiancount.getCancelNums() + vo.getCancelNums());
                        zhuanxiancount
                            .setFinishNums(zhuanxiancount.getFinishNums() + vo.getFinishNums());
                        zhuanxiancount.setMoney(zhuanxiancount.getMoney().add(vo.getMoney()));
                        break;
                    }
                }
            }
            if (serviceSetting.isFreight()) {
                for (CompanyOrderVo vo : freight.getContent()) {
                    if (cov.getCompanyName().equals(vo.getCompanyName())) {
                        cov.setFreight(vo);
                        freightcount
                            .setCancelNums(freightcount.getCancelNums() + vo.getCancelNums());
                        freightcount
                            .setFinishNums(freightcount.getFinishNums() + vo.getFinishNums());
                        freightcount.setMoney(freightcount.getMoney().add(vo.getMoney()));
                        break;
                    }
                }
            }
            volist.add(cov);

        }
        if (serviceSetting.isPaotui()) {
            count.setErrand(errandcount);
        }
        if (serviceSetting.isZhuanche()) {
            count.setZhuanche(zhuanchecount);
        }
        if (serviceSetting.isFreight()) {
            count.setFreight(freightcount);
        }
        if (serviceSetting.isZhuanxian()) {
            count.setZhuanxian(zhuanxiancount);
        }
        volist.add(count);
        return volist;
    }

    @Override
    public List<CompanyOrderVo> exportcompanyOrder(Date start, Date end) {

        List<CompanyOrderVo> volist = new ArrayList<CompanyOrderVo>();

        List<Company> companys = companyMapper.selectAll();
        for (final Company company : companys) {
            CompanyOrderVo cov = new CompanyOrderVo();
            cov.setCompanyName(company.getCompanyName());

            long cancelNums = orderMapper
                .countByCompanyWithStatusAndDate(company.getId(), Order.ORDER_STATUS_CANCELED, null,
                    start, end);
            cov.setCancelNums(cancelNums);

            cov.setFinishNums(
                orderMapper.countFinishedByCompanyWithDate(company.getId(), start, end));
            cov.setMoney(orderFinishedInfoMapper
                .sumAllRealCashByCompanyWithDate(company.getId(), start, end));

            volist.add(cov);
        }

        return volist;
    }

    @Override
    public PageVo<DriverOrderDetailVo> driverOrderDetail(Long driverId, Date start, Date end) {
        PageVo<DriverOrderDetailVo> vopage = new PageVo<DriverOrderDetailVo>();
        List<DriverOrderDetailVo> volist = new ArrayList<DriverOrderDetailVo>();

        long totalElements = orderMapper.countFinishedByDriverWithDate(driverId, start, end);
        List<Order> orderlist = orderMapper
            .selectFinishedByDriverWithDate(driverId, start, end, Pager.getOffset(),
                Pager.getLimit());

        if (!CollectionUtils.isEmpty(orderlist)) {

            SimpleDateFormat formatter = com.ybkj.daijia.constant.DateConstant.DATE_TIME;

            for (Order order : orderlist) {
                DriverOrderDetailVo dovo = new DriverOrderDetailVo();
                dovo.setOrderid(order.getId());
                dovo.setOrderNum(order.getOrderNumber());
                dovo.setMoney(order.getRealCash());
                dovo.setFinishTime(order.getFinishTime());
                dovo.setFinishTimeStr(formatter.format(order.getFinishTime()));

                try {

                    List<DriverPaymentsRecord> records = driverPaymentsRecordMapper
                        .selectByRecordTypeAndOrder(DriverPaymentsRecord.RECHARGE_TYPE_ORDER,
                            order.getId(), DriverPaymentsRecord.ORDER_TYPE_DAIJIA);

                    if (!CollectionUtils.isEmpty(records)) {
                        dovo.setTicheng(records.get(0).getMoney());
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
                volist.add(dovo);
            }
        }

        vopage.setContent(volist);
        vopage.setTotalElements(totalElements);

        return vopage;
    }

    @Override
    public List<DriverOrderDetailVo> exportDriverOrderDetail(Long driverId, Date start, Date end,
        boolean allAmount, Integer amounts) {

        List<DriverOrderDetailVo> volist = new ArrayList<DriverOrderDetailVo>();
        List<Order> orderlist = new ArrayList<Order>();

        if (allAmount) {
            orderlist = orderMapper
                .selectFinishedByDriverWithDate(driverId, start, end, null, null);
        } else {
            orderlist = orderMapper
                .selectFinishedByDriverWithDate(driverId, start, end, 0, amounts);
        }

        if (!CollectionUtils.isEmpty(orderlist)) {
            for (Order order : orderlist) {
                DriverOrderDetailVo dovo = new DriverOrderDetailVo();
                dovo.setOrderid(order.getId());
                dovo.setOrderNum(order.getOrderNumber());
                dovo.setMoney(order.getRealCash());
                dovo.setFinishTime(order.getFinishTime());

                try {
                    List<DriverPaymentsRecord> records = driverPaymentsRecordMapper
                        .selectByRecordTypeAndOrder(DriverPaymentsRecord.RECHARGE_TYPE_ORDER,
                            order.getId(), DriverPaymentsRecord.ORDER_TYPE_DAIJIA);

                    if (!CollectionUtils.isEmpty(records)) {
                        dovo.setTicheng(records.get(0).getMoney());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                volist.add(dovo);
            }
        }

        return volist;
    }

    @Override
    public PageVo<InfoFeeVo> infoFee(Date start, Date end, Long companyId) {
        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("offset", Pager.getOffset());
        params.put("size", Pager.getLimit());

        if (!principal.isCompanyType()) {
            params.put("companyId", principal.getCompanyId());
        } else {
            if (companyId != null) {
                params.put("companyId", companyId);
            }
        }

        List<Driver> content = driverMapper.selectByPage(params);
        long total = driverMapper.countByPage(params);

        PageVo<InfoFeeVo> vopage = new PageVo<InfoFeeVo>();
        vopage.setTotalElements(total);

        List<InfoFeeVo> volist = new ArrayList<InfoFeeVo>();

        if (total > 0) {

            for (Driver driver : content) {

                Company company = companyMapper.selectByPrimaryKey(driver.getCompanyId());

                InfoFeeVo ifvo = new InfoFeeVo();
                ifvo.setName(driver.getRealname());
                ifvo.setCompanyName(company.getCompanyName());

                List<DriverPaymentsRecord> recordlist = driverPaymentsRecordMapper
                    .selectByRecordTypeAndDriver(DriverPaymentsRecord.CONSUMEDRECORD_TYPE_XINXI,
                        driver.getId(), null, start, end);

                if (!CollectionUtils.isEmpty(recordlist)) {
                    for (DriverPaymentsRecord driverPaymentsRecord : recordlist) {
                        ifvo.setMoney(ifvo.getMoney().add(driverPaymentsRecord.getMoney()));
                    }
                }
                volist.add(ifvo);
            }
        }

        vopage.setContent(volist);

        return vopage;
    }

    @Override
    public List<InfoFeeVo> exportInfoFee(Date start, Date end, Long companyId, boolean allAmount,
        Integer amounts) {
        Subject currentUser = SecurityUtils.getSubject();
        final Principal principal = (Principal) currentUser.getPrincipal();

        Map<String, Object> params = new HashMap<String, Object>();
        if (allAmount) {
            params.put("offset", null);
            params.put("size", null);
        } else {
            params.put("offset", 0);
            params.put("size", amounts);
        }

        if (!principal.isCompanyType()) {
            params.put("companyId", principal.getCompanyId());
        } else {
            if (companyId != null) {
                params.put("companyId", companyId);
            }
        }

        List<Driver> content = driverMapper.selectByPage(params);

        List<InfoFeeVo> volist = new ArrayList<InfoFeeVo>();
        params = new HashMap<String, Object>();

        for (final Driver driver : content) {

            Company company = companyMapper.selectByPrimaryKey(driver.getCompanyId());

            InfoFeeVo ifvo = new InfoFeeVo();
            ifvo.setName(driver.getRealname());
            ifvo.setCompanyName(company.getCompanyName());

            List<DriverPaymentsRecord> recordlist = driverPaymentsRecordMapper
                .selectByRecordTypeAndDriver(DriverPaymentsRecord.CONSUMEDRECORD_TYPE_XINXI,
                    driver.getId(), null, start, end);

            if (!CollectionUtils.isEmpty(recordlist)) {
                for (DriverPaymentsRecord driverPaymentsRecord : recordlist) {
                    ifvo.setMoney(ifvo.getMoney().add(driverPaymentsRecord.getMoney()));
                }
            }
            volist.add(ifvo);
        }

        return volist;
    }


    @Override
    public PageVo<OrderTypeVo> orderType(Date start, Date end, Long companyId) {
        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        List<Order> orderpage = orderMapper
            .selectFinishedByCompanyWithFinishTimeGroupOrderType(null, null, null);

        PageVo<OrderTypeVo> vopage = new PageVo<OrderTypeVo>();
        List<OrderTypeVo> volist = new ArrayList<OrderTypeVo>();

        List<Order> orderlist_blank = orderpage;

        if (!CollectionUtils.isEmpty(orderlist_blank)) {
            List<Order> orderlist = new ArrayList<Order>();
            for (Order order : orderlist_blank) {
                if (!StringUtils.isEmpty(order.getOrderType())) {
                    orderlist.add(order);
                }
            }

            for (Order order : orderlist) {
                OrderTypeVo ot = new OrderTypeVo();
                ot.setType(order.getOrderType());
                if (principal.isCompanyType()) {
                    if (companyId != null) {
                        ot.setAmount(orderMapper
                            .countFinishedByCompanyWithOrderType(companyId, order.getOrderType(),
                                start, end));
                        ot.setMoney(orderMapper
                            .sumMoneyByCompanyWithOrderType(companyId, order.getOrderType(), start,
                                end));
                    } else {
                        ot.setAmount(orderMapper
                            .countFinishedByCompanyWithOrderType(null, order.getOrderType(), start,
                                end));
                        ot.setMoney(orderMapper
                            .sumMoneyByCompanyWithOrderType(null, order.getOrderType(), start,
                                end));
                    }
                } else {
                    ot.setAmount(orderMapper
                        .countFinishedByCompanyWithOrderType(principal.getCompanyId(),
                            order.getOrderType(), start, end));
                    ot.setMoney(orderMapper.sumMoneyByCompanyWithOrderType(principal.getCompanyId(),
                        order.getOrderType(), start, end));
                }

                volist.add(ot);
            }
        }

        vopage.setContent(volist);

        return vopage;
    }

    @Override
    public PageVo<UserTypeVo> userType(Date start, Date end, Long companyId) {
        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        List<Order> orderpage = orderMapper
            .selectFinishedByCompanyWithFinishTimeGroupMemberType(null, start, end);

        PageVo<UserTypeVo> vopage = new PageVo<UserTypeVo>();
        List<UserTypeVo> volist = new ArrayList<UserTypeVo>();

        List<Order> orderlist_blank = orderpage;

        if (!CollectionUtils.isEmpty(orderlist_blank)) {
            List<Order> orderlist = new ArrayList<Order>();
            for (Order order : orderlist_blank) {
                if (!StringUtils.isEmpty(order.getMemberType())) {
                    orderlist.add(order);
                }
            }

            for (Order order : orderlist) {
                UserTypeVo ut = new UserTypeVo();
                ut.setType(order.getMemberType());
                if (principal.isCompanyType()) {
                    if (companyId != null) {
                        ut.setAmount(orderMapper
                            .countFinishedByCompanyWithMemberType(companyId, order.getMemberType(),
                                start, end));
                        ut.setMoney(orderMapper
                            .sumMoneyByCompanyWithMemberType(companyId, order.getMemberType(),
                                start, end));
                    } else {
                        ut.setAmount(orderMapper
                            .countFinishedByCompanyWithMemberType(null, order.getMemberType(),
                                start, end));
                        ut.setMoney(orderMapper
                            .sumMoneyByCompanyWithMemberType(null, order.getMemberType(), start,
                                end));
                    }
                } else {
                    ut.setAmount(orderMapper
                        .countFinishedByCompanyWithMemberType(principal.getCompanyId(),
                            order.getMemberType(), start, end));
                    ut.setMoney(orderMapper
                        .sumMoneyByCompanyWithMemberType(principal.getCompanyId(),
                            order.getMemberType(), start, end));
                }

                volist.add(ut);
            }
        }

        vopage.setContent(volist);

        return vopage;
    }

    @Override
    public PageVo<OrderFromSourceVo> orderFromSource(Date start, Date end, Long companyId) {

        Subject currentUser = SecurityUtils.getSubject();
        final Principal principal = (Principal) currentUser.getPrincipal();

        List<Order> orderpage = orderMapper
            .selectFinishedByCompanyWithFinishTimeGroupFromSource(null, null, null, null, null);

        PageVo<OrderFromSourceVo> vopage = new PageVo<OrderFromSourceVo>();
        List<OrderFromSourceVo> volist = new ArrayList<OrderFromSourceVo>();
        BigDecimal allTotal = BigDecimal.ZERO;
        BigDecimal total = BigDecimal.ZERO;
        List<Order> orderlist_blank = orderpage;

        if (!CollectionUtils.isEmpty(orderlist_blank)) {
            List<Order> orderlist = new ArrayList<Order>();
            for (Order order : orderlist_blank) {
                if (!StringUtils.isEmpty(order.getFromSource())) {
                    orderlist.add(order);
                }
            }

            for (Order order : orderlist) {
                OrderFromSourceVo ot = new OrderFromSourceVo();
                ot.setFromSource(order.getFromSource());
                if (principal.isCompanyType()) {
                    if (companyId != null) {
                        ot.setAmount(orderMapper
                            .countFinishedByCompanyWithFinishTimeAndFromSource(companyId, start,
                                end, order.getFromSource()));
                        ot.setMoney(orderMapper
                            .sumMoneyByCompanyWithFinishTimeAndFromSource(companyId, start, end,
                                order.getFromSource()));
                    } else {
                        ot.setAmount(orderMapper
                            .countFinishedByCompanyWithFinishTimeAndFromSource(null, start, end,
                                order.getFromSource()));
                        ot.setMoney(orderMapper
                            .sumMoneyByCompanyWithFinishTimeAndFromSource(null, start, end,
                                order.getFromSource()));
                    }
                } else {
                    ot.setAmount(orderMapper
                        .countFinishedByCompanyWithFinishTimeAndFromSource(principal.getCompanyId(),
                            start, end, order.getFromSource()));
                    ot.setMoney(orderMapper
                        .sumMoneyByCompanyWithFinishTimeAndFromSource(principal.getCompanyId(),
                            start, end, order.getFromSource()));
                }
                allTotal = allTotal.add(ot.getMoney());
                total = total.add(new BigDecimal(ot.getAmount()));
                volist.add(ot);
            }
        }

        vopage.setContent(volist);
        vopage.setTotalElements(volist.size());
        vopage.setAllTotal(allTotal);
        vopage.setTotal(total);

        return vopage;
    }

    @Override
    public List<OrderFromSourceVo> exportSource(Date start, Date end, final Long companyId,
        final Integer amounts) {

        Subject currentUser = SecurityUtils.getSubject();
        final Principal principal = (Principal) currentUser.getPrincipal();

        List<Order> orderpage = orderMapper
            .selectFinishedByCompanyWithFinishTimeGroupFromSource(null, null, null,
                Pager.getOffset(), amounts);

        List<OrderFromSourceVo> volist = new ArrayList<OrderFromSourceVo>();

        List<Order> orderlist_blank = orderpage;

        if (!CollectionUtils.isEmpty(orderlist_blank)) {
            List<Order> orderlist = new ArrayList<Order>();
            for (Order order : orderlist_blank) {
                if (!StringUtils.isEmpty(order.getFromSource())) {
                    orderlist.add(order);
                }
            }

            for (Order order : orderlist) {
                OrderFromSourceVo ot = new OrderFromSourceVo();
                ot.setFromSource(order.getFromSource());
                if (principal.isCompanyType()) {
                    if (companyId != null) {
                        ot.setAmount(orderMapper
                            .countFinishedByCompanyWithFinishTimeAndFromSource(companyId, start,
                                end, order.getFromSource()));
                        ot.setMoney(orderMapper
                            .sumMoneyByCompanyWithFinishTimeAndFromSource(companyId, start, end,
                                order.getFromSource()));
                    } else {
                        ot.setAmount(orderMapper
                            .countFinishedByCompanyWithFinishTimeAndFromSource(null, start, end,
                                order.getFromSource()));
                        ot.setMoney(orderMapper
                            .sumMoneyByCompanyWithFinishTimeAndFromSource(null, start, end,
                                order.getFromSource()));
                    }
                } else {
                    ot.setAmount(orderMapper
                        .countFinishedByCompanyWithFinishTimeAndFromSource(principal.getCompanyId(),
                            start, end, order.getFromSource()));
                    ot.setMoney(orderMapper
                        .sumMoneyByCompanyWithFinishTimeAndFromSource(principal.getCompanyId(),
                            start, end, order.getFromSource()));
                }

                volist.add(ot);
            }
        }

        return volist;
    }


    @Override
    public List<MemberOrderVo> newMemberOrder(Date start, Date end, Long companyId) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        StringBuilder sb = new StringBuilder();
        sb.append(passengerApi.getPassengerBaseURL() + PassengerApi.QUERY_PASSENGER
            + "?appKey={appKey}&appId={appId}&sign={sign}&page={page}&rows={rows}");

        Map<String, String> kv = new HashMap<String, String>();
        kv.put("page", String.valueOf(Pager.getPage() + 1));
        kv.put("rows", String.valueOf(Pager.getLimit()));
        if (principal.isCompanyType()) {
            if (null != companyId) {
                kv.put("companyId", String.valueOf(companyId));
                sb.append("&companyId={companyId}");
            }
        } else {
            kv.put("companyId", String.valueOf(principal.getCompanyId()));
            sb.append("&companyId={companyId}");
        }

        String result = passengerApi.get(sb.toString(), kv, settingUtils.get());

        List<Passenger> content = new ArrayList<Passenger>();
        long total = 0;

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");
                total = data.getLong("total");
                JSONArray ja = data.getJSONArray("rows");
                Gson gson = new Gson();
                content = gson.fromJson(ja.toString(), new TypeToken<List<Passenger>>() {
                }.getType());
            }
        }

        List<MemberOrderVo> vopage = new ArrayList<MemberOrderVo>();

        if (!CollectionUtils.isEmpty(content)) {
            for (Passenger passenger : content) {
                MemberOrderVo mo = new MemberOrderVo();

                Company company = companyMapper.selectByPrimaryKey(passenger.getCompanyId());
                if (null != company) {
                    mo.setCompanyName(company.getCompanyName());
                }

                mo.setName(passenger.getName());
                mo.setPhone(passenger.getPhone());
                mo.setFinishNums(
                    orderMapper.countFinishedByMemberWithFinishTime(passenger.getId(), start, end));
                mo.setMoney(
                    orderMapper.sumMoneyByMemberWithFinishTime(passenger.getId(), start, end));

                vopage.add(mo);
            }
        }

        return vopage;
    }

    @Override
    public List<MemberOrderVo> exportMemberOrder(Date start, Date end, String name,
        boolean allAmount, Integer amounts, Long companyId) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        StringBuilder sb = new StringBuilder();
        sb.append(passengerApi.getPassengerBaseURL() + PassengerApi.QUERY_PASSENGER
            + "?appKey={appKey}&appId={appId}&sign={sign}&page={page}&rows={rows}");

        Map<String, String> kv = new HashMap<String, String>();
        kv.put("page", String.valueOf(Pager.getPage() + 1));
        kv.put("rows", String.valueOf(Pager.getLimit()));
        if (principal.isCompanyType()) {
            if (null != companyId) {
                kv.put("companyId", String.valueOf(companyId));
                sb.append("&companyId={companyId}");
            }
        } else {
            kv.put("companyId", String.valueOf(principal.getCompanyId()));
            sb.append("&companyId={companyId}");
        }
        if (!StringUtils.isEmpty(name)) {
            kv.put("param", name);
            sb.append("&param={param}");
        }

        String result = passengerApi.get(sb.toString(), kv, settingUtils.get());

        List<Passenger> content = new ArrayList<Passenger>();

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");
                JSONArray ja = data.getJSONArray("rows");
                Gson gson = new Gson();
                content = gson.fromJson(ja.toString(), new TypeToken<List<Passenger>>() {
                }.getType());
            }
        }

        List<MemberOrderVo> volist = new ArrayList<MemberOrderVo>();

        if (!CollectionUtils.isEmpty(content)) {
            for (Passenger passenger : content) {
                MemberOrderVo mo = new MemberOrderVo();

                Company company = companyMapper.selectByPrimaryKey(passenger.getCompanyId());
                if (null != company) {
                    mo.setCompanyName(company.getCompanyName());
                }

                mo.setName(passenger.getName());
                mo.setPhone(passenger.getPhone());

                mo.setFinishNums(
                    orderMapper.countFinishedByMemberWithFinishTime(passenger.getId(), start, end));
                mo.setMoney(
                    orderMapper.sumMoneyByMemberWithFinishTime(passenger.getId(), start, end));

                volist.add(mo);
            }
        }

        return volist;
    }

    public List<TableOrderMonthVo> tableOrderMonth(Calendar calendar, final Long companyId) {

        Setting setting = settingUtils.get();

        Subject currentUser = SecurityUtils.getSubject();
        final Principal principal = (Principal) currentUser.getPrincipal();

        List<TableOrderMonthVo> volist = new ArrayList<TableOrderMonthVo>();
        for (int i = 1; i <= 12; i++) {
            TableOrderMonthVo tom = new TableOrderMonthVo();
            tom.setTime(i);
            volist.add(tom);
        }

        for (TableOrderMonthVo tom : volist) {
            Calendar startCalendar = Calendar.getInstance();
            startCalendar.setTime(calendar.getTime());
            Calendar endCalendar = Calendar.getInstance();
            endCalendar.setTime(calendar.getTime());

            startCalendar.set(Calendar.MONTH, tom.getTime() - 1);
            startCalendar.set(Calendar.DAY_OF_MONTH, 1);
            startCalendar.set(Calendar.HOUR_OF_DAY, 0);
            startCalendar.set(Calendar.MINUTE, 0);
            startCalendar.set(Calendar.SECOND, 0);
            startCalendar.set(Calendar.HOUR_OF_DAY, setting.getWorkBegin());
            final Date begin = startCalendar.getTime();
            startCalendar.add(Calendar.MONTH, 1);
            final Date end = startCalendar.getTime();

            if (!principal.isCompanyType()) {

                tom.setFinishedAmount(orderMapper
                    .countFinishedByCompanyWithDate(principal.getCompanyId(), begin, end));
                tom.setMoney(orderFinishedInfoMapper
                    .sumAllRealCashByCompanyWithDate(principal.getCompanyId(), begin, end));
            } else {
                if (companyId != null) {

                    tom.setFinishedAmount(
                        orderMapper.countFinishedByCompanyWithDate(companyId, begin, end));
                    tom.setMoney(orderFinishedInfoMapper
                        .sumAllRealCashByCompanyWithDate(companyId, begin, end));
                } else {

                    tom.setFinishedAmount(
                        orderMapper.countFinishedByCompanyWithDate(null, begin, end));
                    tom.setMoney(
                        orderFinishedInfoMapper.sumAllRealCashByCompanyWithDate(null, begin, end));

                }
            }

            long cancelCount = 0;
            if (!principal.isCompanyType()) {
                cancelCount = orderMapper
                    .countCanceledByCompanyWithDate(principal.getCompanyId(), begin, end);
            } else {
                if (companyId != null) {
                    cancelCount = orderMapper.countCanceledByCompanyWithDate(companyId, begin, end);
                } else {
                    cancelCount = orderMapper.countCanceledByCompanyWithDate(null, begin, end);
                }
            }

            tom.setCancelAmount(cancelCount);
        }

        return volist;
    }

    @Override
    public List<TableOrderMonthVo> exportTableOrderMonth(Calendar calendar, Long companyId) {

        Setting setting = settingUtils.get();

        Subject currentUser = SecurityUtils.getSubject();
        final Principal principal = (Principal) currentUser.getPrincipal();

        List<TableOrderMonthVo> volist = new ArrayList<TableOrderMonthVo>();
        for (int i = 1; i <= 12; i++) {
            TableOrderMonthVo tom = new TableOrderMonthVo();
            tom.setTime(i);
            volist.add(tom);
        }

        for (TableOrderMonthVo tom : volist) {
            Calendar startCalendar = Calendar.getInstance();
            startCalendar.setTime(calendar.getTime());
            Calendar endCalendar = Calendar.getInstance();
            endCalendar.setTime(calendar.getTime());

            startCalendar.set(Calendar.MONTH, tom.getTime() - 1);
            startCalendar.set(Calendar.DAY_OF_MONTH, 1);
            startCalendar.set(Calendar.HOUR_OF_DAY, 0);
            startCalendar.set(Calendar.MINUTE, 0);
            startCalendar.set(Calendar.SECOND, 0);
            startCalendar.set(Calendar.HOUR_OF_DAY, setting.getWorkBegin());
            Date begin = startCalendar.getTime();
            startCalendar.add(Calendar.MONTH, 1);
            Date end = startCalendar.getTime();

            if (!principal.isCompanyType()) {
                tom.setFinishedAmount(orderMapper
                    .countFinishedByCompanyWithDate(principal.getCompanyId(), begin, end));
                tom.setMoney(orderFinishedInfoMapper
                    .sumAllRealCashByCompanyWithDate(principal.getCompanyId(), begin, end));
            } else {
                if (companyId != null) {
                    tom.setFinishedAmount(
                        orderMapper.countFinishedByCompanyWithDate(companyId, begin, end));
                    tom.setMoney(orderFinishedInfoMapper
                        .sumAllRealCashByCompanyWithDate(companyId, begin, end));
                } else {
                    tom.setFinishedAmount(
                        orderMapper.countFinishedByCompanyWithDate(null, begin, end));
                    tom.setMoney(
                        orderFinishedInfoMapper.sumAllRealCashByCompanyWithDate(null, begin, end));
                }
            }

            long cancelCount = 0;
            if (!principal.isCompanyType()) {
                cancelCount = orderMapper
                    .countCanceledByCompanyWithDate(principal.getCompanyId(), begin, end);
            } else {
                if (companyId != null) {
                    cancelCount = orderMapper.countCanceledByCompanyWithDate(companyId, begin, end);
                } else {
                    cancelCount = orderMapper.countCanceledByCompanyWithDate(null, begin, end);
                }
            }

            tom.setCancelAmount(cancelCount);
        }

        return volist;
    }

    @Override
    public List<TableOrderMonthVo> tableOrderDay(Calendar calendar, Long companyId) {

        Setting setting = settingUtils.get();

        Subject currentUser = SecurityUtils.getSubject();
        final Principal principal = (Principal) currentUser.getPrincipal();

        List<TableOrderMonthVo> volist = new ArrayList<TableOrderMonthVo>();
        for (int i = 1; i <= calendar.getActualMaximum(Calendar.DATE); i++) {
            TableOrderMonthVo tom = new TableOrderMonthVo();
            tom.setTime(i);
            volist.add(tom);
        }

        for (TableOrderMonthVo tom : volist) {
            Calendar startCalendar = Calendar.getInstance();
            startCalendar.setTime(calendar.getTime());
            Calendar endCalendar = Calendar.getInstance();
            endCalendar.setTime(calendar.getTime());

            startCalendar.set(Calendar.DAY_OF_MONTH, tom.getTime());
            startCalendar.set(Calendar.HOUR_OF_DAY, 0);
            startCalendar.set(Calendar.MINUTE, 0);
            startCalendar.set(Calendar.SECOND, 0);
            startCalendar.set(Calendar.HOUR_OF_DAY, setting.getWorkBegin());
            final Date begin = startCalendar.getTime();

            startCalendar.add(Calendar.DAY_OF_MONTH, 1);
            final Date end = startCalendar.getTime();

            if (!principal.isCompanyType()) {
                tom.setFinishedAmount(orderMapper
                    .countFinishedByCompanyWithDate(principal.getCompanyId(), begin, end));
                tom.setMoney(orderFinishedInfoMapper
                    .sumAllRealCashByCompanyWithDate(principal.getCompanyId(), begin, end));
                tom.setCancelAmount(orderMapper
                    .countCanceledByCompanyWithDate(principal.getCompanyId(), begin, end));
            } else {
                if (companyId != null) {
                    tom.setFinishedAmount(
                        orderMapper.countFinishedByCompanyWithDate(companyId, begin, end));
                    tom.setMoney(orderFinishedInfoMapper
                        .sumAllRealCashByCompanyWithDate(companyId, begin, end));
                    tom.setCancelAmount(
                        orderMapper.countCanceledByCompanyWithDate(companyId, begin, end));
                } else {
                    tom.setFinishedAmount(
                        orderMapper.countFinishedByCompanyWithDate(null, begin, end));
                    tom.setMoney(
                        orderFinishedInfoMapper.sumAllRealCashByCompanyWithDate(null, begin, end));
                    tom.setCancelAmount(
                        orderMapper.countCanceledByCompanyWithDate(null, begin, end));
                }
            }

        }

        return volist;
    }

    @Override
    public List<TableOrderMonthVo> exportTableOrderDay(Calendar calendar,
        boolean allAmount, Integer amounts) {

        Setting setting = settingUtils.get();

        Subject currentUser = SecurityUtils.getSubject();
        final Principal principal = (Principal) currentUser.getPrincipal();

        List<TableOrderMonthVo> volist = new ArrayList<TableOrderMonthVo>();
        for (int i = 1; i <= calendar.getActualMaximum(Calendar.DATE); i++) {
            TableOrderMonthVo tom = new TableOrderMonthVo();
            tom.setTime(i);
            volist.add(tom);
        }

        for (TableOrderMonthVo tom : volist) {
            Calendar startCalendar = Calendar.getInstance();
            startCalendar.setTime(calendar.getTime());
            Calendar endCalendar = Calendar.getInstance();
            endCalendar.setTime(calendar.getTime());

            startCalendar.set(Calendar.DAY_OF_MONTH, tom.getTime());
            startCalendar.set(Calendar.HOUR_OF_DAY, 0);
            startCalendar.set(Calendar.MINUTE, 0);
            startCalendar.set(Calendar.SECOND, 0);
            startCalendar.set(Calendar.HOUR_OF_DAY, setting.getWorkBegin());
            final Date begin = startCalendar.getTime();

            startCalendar.add(Calendar.DAY_OF_MONTH, 1);
            final Date end = startCalendar.getTime();

            tom.setFinishedAmount(
                orderMapper.countFinishedByCompanyWithDate(principal.getCompanyId(), begin, end));
            tom.setMoney(orderFinishedInfoMapper
                .sumAllRealCashByCompanyWithDate(principal.getCompanyId(), begin, end));
            tom.setCancelAmount(
                orderMapper.countCanceledByCompanyWithDate(principal.getCompanyId(), begin, end));

        }

        return volist;
    }


    @Override
    public PageVo<Activity> activity(Long companyId, String title, Date start, Date end) {

//		Subject currentUser = SecurityUtils.getSubject();
//		Principal principal = (Principal) currentUser.getPrincipal();
//
//		long totalElements=0;
//		List<Activity> content=new ArrayList<Activity>();
//
//		String likeTitle = null;
//		if(!StringUtils.isEmpty(title)){
//			likeTitle = "%"+title+"%";
//		}
//
//		if (!principal.isCompanyType()) {
//			totalElements=activityMapper.countByCompanyWithParams(principal.getCompanyId(), likeTitle);
//			content=activityMapper.selectByCompanyWithParams(principal.getCompanyId(), likeTitle, Pager.getOffset(), Pager.getLimit());
//		} else {
//			if (null != companyId) {
//				totalElements=activityMapper.countByCompanyWithParams(companyId, likeTitle);
//				content=activityMapper.selectByCompanyWithParams(companyId, likeTitle, Pager.getOffset(), Pager.getLimit());
//			}
//			else{
//				totalElements=activityMapper.countByCompanyWithParams(null, likeTitle);
//				content=activityMapper.selectByCompanyWithParams(null, likeTitle, Pager.getOffset(), Pager.getLimit());
//			}
//		}
//
        PageVo<Activity> vopage = new PageVo<Activity>();
//		List<Activity> volist = new ArrayList<Activity>();
//
//		if (totalElements > 0) {
//			for (Activity activity : content) {
//				Long joinAmount = 0L;
//				BigDecimal totalMoney = BigDecimal.ZERO;
//				if (null == start && null == end) {
//					joinAmount = activityRecordMapper.countByActivityWithDate(activity.getId(), null, null);
//					totalMoney = activityRecordMapper.sumMoneyByActivityWithDate(activity.getId(), null, null);
//				} else if (null != start && null != end) {
//					joinAmount = activityRecordMapper.countByActivityWithDate(activity.getId(), start, end);
//					totalMoney = activityRecordMapper.sumMoneyByActivityWithDate(activity.getId(), start, end);
//				} else if (null == start && null != end) {
//					joinAmount = activityRecordMapper.countByActivityWithDate(activity.getId(), null, end);
//					totalMoney = activityRecordMapper.sumMoneyByActivityWithDate(activity.getId(), null, end);
//				} else if (null != start && null == end) {
//					joinAmount = activityRecordMapper.countByActivityWithDate(activity.getId(), start, null);
//					totalMoney = activityRecordMapper.sumMoneyByActivityWithDate(activity.getId(), start, null);
//				}
//
//				activity.setJoinAmount(joinAmount);
//				activity.setTotalMoney(totalMoney);
//				activity.setCompany(companyMapper.selectByPrimaryKey(activity.getCompanyId()));
//
//				volist.add(activity);
//			}
//		}
//
//		vopage.setContent(volist);
//		vopage.setTotalElements(totalElements);

        return vopage;

    }

    @Override
    public List<Activity> exportActivty(Long companyId, String title, Date start, Date end,
        boolean allAmount, Integer amounts) {

//		Subject currentUser = SecurityUtils.getSubject();
//		Principal principal = (Principal) currentUser.getPrincipal();
//
//		List<Activity> content=new ArrayList<Activity>();
//
//		String likeTitle = null;
//		if(!StringUtils.isEmpty(title)){
//			likeTitle = "%"+title+"%";
//		}
//
//		if (!principal.isCompanyType()) {
//			content=activityMapper.selectByCompanyWithParams(principal.getCompanyId(), likeTitle, Pager.getOffset(),amounts);
//		} else {
//			if (null != companyId) {
//				content=activityMapper.selectByCompanyWithParams(companyId, likeTitle, Pager.getOffset(), amounts);
//			}
//			else{
//				content=activityMapper.selectByCompanyWithParams(null, likeTitle, Pager.getOffset(), amounts);
//			}
//		}
//
        List<Activity> volist = new ArrayList<Activity>();
//
//		for (Activity activity : content) {
//			Long joinAmount = 0L;
//			BigDecimal totalMoney = BigDecimal.ZERO;
//			if (null == start && null == end) {
//				joinAmount = activityRecordMapper.countByActivityWithDate(activity.getId(), null, null);
//				totalMoney = activityRecordMapper.sumMoneyByActivityWithDate(activity.getId(), null, null);
//			} else if (null != start && null != end) {
//				joinAmount = activityRecordMapper.countByActivityWithDate(activity.getId(), start, end);
//				totalMoney = activityRecordMapper.sumMoneyByActivityWithDate(activity.getId(), start, end);
//			} else if (null == start && null != end) {
//				joinAmount = activityRecordMapper.countByActivityWithDate(activity.getId(), null, end);
//				totalMoney = activityRecordMapper.sumMoneyByActivityWithDate(activity.getId(), null, end);
//			} else if (null != start && null == end) {
//				joinAmount = activityRecordMapper.countByActivityWithDate(activity.getId(), start, null);
//				totalMoney = activityRecordMapper.sumMoneyByActivityWithDate(activity.getId(), start, null);
//			}
//
//			activity.setJoinAmount(joinAmount);
//			activity.setTotalMoney(totalMoney);
//			activity.setCompany(companyMapper.selectByPrimaryKey(activity.getCompanyId()));
//
//			volist.add(activity);
//		}

        return volist;
    }

    @Override
    public Long countIntroduce(Long companyId, String introducer) {
        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        String likeIntroducer = null;
        if (!StringUtils.isEmpty(introducer)) {
            likeIntroducer = "%" + introducer + "%";
        }

        List<Driver> driverList = new ArrayList<Driver>();

        if (!principal.isCompanyType()) {
            driverList = driverMapper
                .selectByCompanyWithIntroducerGroupIntroducer(principal.getCompanyId(),
                    likeIntroducer);
        } else {
            if (null != companyId) {
                driverList = driverMapper
                    .selectByCompanyWithIntroducerGroupIntroducer(companyId, likeIntroducer);
            } else {
                driverList = driverMapper
                    .selectByCompanyWithIntroducerGroupIntroducer(null, likeIntroducer);
            }
        }

        long totalElements = 0;

        if (!CollectionUtils.isEmpty(driverList)) {
            for (Driver driver : driverList) {
                if (driver.getDriverJobType().contains(Driver.DriverJobType.daijia.toString())) {
                    if (null != driverMapper.selectByUsername(driver.getIntroducer())) {
                        totalElements++;
                    }
                }
            }
        }

        return totalElements;

    }


    @Override
    public PageVo<DriverOrderVo> introduce(Long companyId, String introducer, Date start,
        Date end) {

        Pager.setLimit(10);

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        String likeIntroducer = null;
        if (!StringUtils.isEmpty(introducer)) {
            likeIntroducer = "%" + introducer + "%";
        }

        List<Driver> driverList = new ArrayList<Driver>();

        if (!principal.isCompanyType()) {
            companyId = principal.getCompanyId();
        }
        driverList = driverMapper
            .selectByCompanyWithIntroducerGroupIntroducer(companyId, likeIntroducer);
        List<Driver> introduceList = new ArrayList<Driver>();//推荐人

        if (!CollectionUtils.isEmpty(driverList)) {
            for (Driver driver : driverList) {
                if (null != driver && StringUtils.isNotBlank(driver.getIntroducer())) {
                    Driver iDriver = driverMapper.selectByUsername(driver.getIntroducer());
                    if (null != iDriver) {
                        introduceList.add(iDriver);
                    }
                }
            }
        }

        int total = introduceList.size();
        if (total > 0) {
            if (total > Pager.getOffset() + Pager.getLimit()) {
                introduceList = introduceList
                    .subList(Pager.getOffset(), Pager.getOffset() + Pager.getLimit());
            } else {
                introduceList = introduceList.subList(Pager.getOffset(), introduceList.size());
            }
        }

        PageVo<DriverOrderVo> vopage = new PageVo<DriverOrderVo>();
        vopage.setTotalElements(total);
        List<DriverOrderVo> volist = new ArrayList<DriverOrderVo>();

        ServiceSetting serviceSetting = ServiceUtil.checkOpen();

        PageVo<DriverOrderVo> zhuanche = null;
        PageVo<DriverOrderVo> errand = null;
        PageVo<DriverOrderVo> freight = null;
        PageVo<DriverOrderVo> zhuanxian = null;
        if (serviceSetting.isZhuanche()) {
            zhuanche = zhuancheService.zhuancheIntroduce(companyId, start, end);
        }
        if (serviceSetting.isPaotui()) {
            errand = errandService.errandIntroduce(companyId, start, end);
        }
        if (serviceSetting.isFreight()) {
            freight = freightService.freightIntroduce(companyId, start, end);
        }
        if (serviceSetting.isZhuanxian()) {
            zhuanxian = zhuanxianService.zhuanxianIntroduce(companyId, start, end);
        }
        if (total > 0) {
            for (Driver driver : introduceList) {
                //推荐人本人
                DriverOrderVo dovo = new DriverOrderVo();
                dovo.setDriverid(driver.getId());
                dovo.setName("");
                dovo.setUsername("");
                dovo.setIntroduced(driver.getRealname() + "(" + driver.getUsername() + ")");
                dovo.setCompanyName("");
//				dovo.setVirtual(driver.getVirtual());
                dovo.setType("");
//				introduceDataDetail(dovo,start,end);

                //推荐的人
                List<Driver> introducedList = driverMapper.selectByIntroducer(driver.getUsername());
                List<DriverOrderVo> drivers = new ArrayList<DriverOrderVo>();
                if (!CollectionUtils.isEmpty(introducedList)) {
                    for (Driver driver2 : introducedList) {
                        DriverOrderVo dovo2 = new DriverOrderVo();
                        dovo2.setDriverid(driver2.getId());
                        dovo2.setName(driver2.getRealname());
                        dovo2.setUsername(driver2.getUsername());

                        Company thisCompany = companyMapper
                            .selectByPrimaryKey(driver2.getCompanyId());
                        dovo2.setCompanyName(thisCompany.getCompanyName());

                        dovo2.setVirtual(driver2.getVirtual());
                        dovo2.setType(driver2.getType());

                        if (serviceSetting.isDaijia()) {
                            introduceDataDetail(dovo2, start, end);
                            dovo.setVirtual(dovo.getVirtual().add(dovo2.getVirtual()));
                            dovo.setFinishNums(dovo.getFinishNums() + dovo2.getFinishNums());
                            dovo.setMoney(dovo.getMoney().add(dovo2.getMoney()));
                            dovo.setTicheng(dovo.getTicheng().add(dovo2.getTicheng()));
                        }

                        if (null != zhuanche) {
                            for (DriverOrderVo vo : zhuanche.getContent()) {
                                if (vo.getDriverid().equals(dovo2.getDriverid())) {
                                    dovo2.setZhuanche(vo);
                                    break;
                                }

                            }
                        }

                        if (null != errand) {
                            for (DriverOrderVo vo : errand.getContent()) {
                                if (vo.getDriverid().equals(dovo2.getDriverid())) {
                                    dovo2.setErrand(vo);
                                    break;
                                }

                            }
                        }

                        if (null != freight) {
                            for (DriverOrderVo vo : freight.getContent()) {
                                if (vo.getDriverid().equals(dovo2.getDriverid())) {
                                    dovo2.setFreight(vo);
                                    break;
                                }

                            }
                        }
                        if (null != zhuanxian) {
                            for (DriverOrderVo vo : zhuanxian.getContent()) {
                                if (vo.getDriverid().equals(dovo2.getDriverid())) {
                                    dovo2.setZhuanxian(vo);
                                    break;
                                }

                            }
                        }
                        drivers.add(dovo2);

                    }
                    dovo.setDrivers(drivers);
                }

                volist.add(dovo);
            }
            vopage.setContent(volist);
        } else {
            vopage.setContent(volist);
        }
        return vopage;
    }

    @Override
    public List<DriverOrderVo> exportIntroduce(Long companyId, String introducer,
        Date start, Date end, boolean allAmount, Integer amounts) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        String likeIntroducer = null;
        if (!StringUtils.isEmpty(introducer)) {
            likeIntroducer = "%" + introducer + "%";
        }

        List<Driver> driverList = new ArrayList<Driver>();

        if (!principal.isCompanyType()) {
            driverList = driverMapper
                .selectByCompanyWithIntroducerGroupIntroducer(principal.getCompanyId(),
                    likeIntroducer);
        } else {
            if (null != companyId) {
                driverList = driverMapper
                    .selectByCompanyWithIntroducerGroupIntroducer(companyId, likeIntroducer);
            } else {
                driverList = driverMapper
                    .selectByCompanyWithIntroducerGroupIntroducer(null, likeIntroducer);
            }
        }

        List<Driver> introduceList = new ArrayList<Driver>();

        if (!CollectionUtils.isEmpty(driverList)) {
            for (Driver driver : driverList) {
                if (org.apache.commons.lang3.StringUtils.isNotBlank(driver.getIntroducer())) {
                    Driver iDriver = driverMapper.selectByUsername(driver.getIntroducer());
                    if (null != iDriver) {
                        introduceList.add(iDriver);
                    }
                }
            }
        }

        int total = introduceList.size();

        if (total > 0) {
            if (allAmount) {
                //导出全部
            } else {
                if (total > amounts) {
                    //导出数量
                    introduceList = introduceList.subList(0, amounts);
                } else {
                    //导出数量
                    introduceList = introduceList.subList(0, introduceList.size());
                }
            }
        }

        List<DriverOrderVo> volist = new ArrayList<DriverOrderVo>();

        if (total > 0) {
            for (final Driver driver : introduceList) {
                //推荐人本人
                DriverOrderVo dovo = new DriverOrderVo();
                dovo.setDriverid(driver.getId());
                dovo.setName("");
                dovo.setUsername("");
                dovo.setIntroduced(driver.getRealname() + "(" + driver.getUsername() + ")");
                dovo.setCompanyName("");
//				dovo.setVirtual(driver.getVirtual());
                dovo.setType("");
//				introduceDataDetail(dovo,start,end);
                volist.add(dovo);

                //推荐的人
                List<Driver> introducedList = driverMapper.selectByIntroducer(driver.getUsername());

                if (!CollectionUtils.isEmpty(introducedList)) {
                    for (Driver driver2 : introducedList) {
                        DriverOrderVo dovo2 = new DriverOrderVo();
                        dovo2.setDriverid(driver2.getId());
                        dovo2.setName(driver2.getRealname());
                        dovo2.setUsername(driver2.getUsername());

                        Company thisCompany = companyMapper
                            .selectByPrimaryKey(driver2.getCompanyId());
                        dovo2.setCompanyName(thisCompany.getCompanyName());

                        dovo2.setVirtual(driver2.getVirtual());
                        dovo2.setType(driver2.getType());
                        introduceDataDetail(dovo2, start, end);
                        volist.add(dovo2);

                        dovo.setVirtual(dovo.getVirtual().add(dovo2.getVirtual()));
                        dovo.setFinishNums(dovo.getFinishNums() + dovo2.getFinishNums());
                        dovo.setMoney(dovo.getMoney().add(dovo2.getMoney()));
                        dovo.setTicheng(dovo.getTicheng().add(dovo2.getTicheng()));

                    }
                }


            }

        }

        return volist;
    }

    private void introduceDataDetail(DriverOrderVo dovo, Date start, Date end) {
        List<Order> orderlist = orderMapper
            .selectFinishedByDriverWithDate(dovo.getDriverid(), start, end, null, null);

        //订单数 订单接
        if (!CollectionUtils.isEmpty(orderlist)) {
            for (Order order : orderlist) {
                dovo.setMoney(dovo.getMoney().add(order.getRealCash()));
            }
            dovo.setFinishNums(orderlist.size());
        } else {
            dovo.setFinishNums(0);
        }

        //提成
        List<DriverPaymentsRecord> recordlist = driverPaymentsRecordMapper
            .selectByRecordTypeAndDriver(DriverPaymentsRecord.RECHARGE_TYPE_ORDER,
                dovo.getDriverid(), null, start, end);
        if (!CollectionUtils.isEmpty(recordlist)) {
            for (DriverPaymentsRecord driverPaymentsRecord : recordlist) {
                dovo.setTicheng(dovo.getTicheng().add(driverPaymentsRecord.getMoney()));
            }
        }

    }

    @Override
    public Map<String, Object> compositive(Long companyId, Date start, Date end) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        Map<String, Object> map = new HashMap<String, Object>();

        //setup1
        Long orderFinishedAmount_this;//本公司单并且是本公司司机完成单量
        Long orderBusyAmount_this;//本公司单并且是本公司司机执行中单量（包括预派单）
        Long orderNewAmount_this;//本公司新单量
        Long orderFinishedAmount_getout;//本公司单并且是其他公司司机完成单量
        Long orderBusyAmount_getout;//本公司单并且是其他公司司机执行中单量（包括预派单）
        Long orderCanceledAmount;//本公司订单销单量
        Long orderFinishedAmount_comein;//其他公司单并且是本公司司机完成单量
        Long orderBusyAmount_comein;//其他公司单并且是本公司司机执行中单量（包括预派单）
        Long orderTotalAmount = 0L;//总单量

        orderFinishedAmount_this = orderMapper
            .countFinishedByThisCompanyThisDriverWithDate(companyId, start, end);
        orderBusyAmount_this = orderMapper
            .countBusyByThisCompanyThisDriverWithDate(companyId, start, end);
        orderNewAmount_this = orderMapper
            .countByCompanyWithStatusAndDate(companyId, Order.ORDER_STATUS_NEW, null, start, end);
        orderFinishedAmount_getout = orderMapper
            .countFinishedByThisCompanyOtherDriverWithDate(companyId, start, end);
        orderBusyAmount_getout = orderMapper
            .countBusyByThisCompanyOtherDriverWithDate(companyId, start, end);
        orderCanceledAmount = orderMapper.countCanceledByCompanyWithDate(companyId, start, end);
        orderFinishedAmount_comein = orderMapper
            .countFinishedByOtherCompanyThisDriverWithDate(companyId, start, end);
        orderBusyAmount_comein = orderMapper
            .countBusyByOtherCompanyThisDriverWithDate(companyId, start, end);
        orderTotalAmount = orderFinishedAmount_this + orderBusyAmount_this + orderNewAmount_this
            + orderFinishedAmount_getout
            + orderBusyAmount_getout + orderCanceledAmount + orderFinishedAmount_comein
            + orderBusyAmount_comein;

        map.put("orderFinishedAmount_this", orderFinishedAmount_this);
        map.put("orderBusyAmount_this", orderBusyAmount_this + orderNewAmount_this);
        map.put("orderFinishedAmount_getout", orderFinishedAmount_getout);
        map.put("orderBusyAmount_getout", orderBusyAmount_getout);
        map.put("orderCanceledAmount", orderCanceledAmount);
        map.put("orderFinishedAmount_comein", orderFinishedAmount_comein);
        map.put("orderBusyAmount_comein", orderBusyAmount_comein);
        map.put("orderTotalAmount", orderTotalAmount);

        //setup2
        BigDecimal orderFinishedMoney_this = BigDecimal.ZERO;
        BigDecimal orderBusyMoney_this = BigDecimal.ZERO;
        BigDecimal orderFinishedMoney_getout = BigDecimal.ZERO;
        BigDecimal orderBusyMoney_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledMoney = BigDecimal.ZERO;
        BigDecimal orderFinishedMoney_comein = BigDecimal.ZERO;
        BigDecimal orderBusyMoney_comein = BigDecimal.ZERO;
        BigDecimal orderTotalMoney = BigDecimal.ZERO;

        orderFinishedMoney_this = orderFinishedInfoMapper
            .sumRealCashByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedMoney_this) {
            orderFinishedMoney_this = BigDecimal.ZERO;
        }
        orderFinishedMoney_getout = orderFinishedInfoMapper
            .sumRealCashGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedMoney_getout) {
            orderFinishedMoney_getout = BigDecimal.ZERO;
        }
        orderFinishedMoney_comein = orderFinishedInfoMapper
            .sumRealCashComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedMoney_comein) {
            orderFinishedMoney_comein = BigDecimal.ZERO;
        }
        orderTotalMoney = orderFinishedMoney_this.add(orderFinishedMoney_getout)
            .add(orderFinishedMoney_comein);

        map.put("orderFinishedMoney_this",
            orderFinishedMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyMoney_this",
            orderBusyMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedMoney_getout",
            orderFinishedMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyMoney_getout",
            orderBusyMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledMoney",
            orderCanceledMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedMoney_comein",
            orderFinishedMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyMoney_comein",
            orderBusyMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalMoney",
            orderTotalMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup3
        BigDecimal orderFinishedCouponMoney_this = BigDecimal.ZERO;
        BigDecimal orderBusyCouponMoney_this = BigDecimal.ZERO;
        BigDecimal orderFinishedCouponMoney_getout = BigDecimal.ZERO;
        BigDecimal orderBusyCouponMoney_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledCouponMoney = BigDecimal.ZERO;
        BigDecimal orderFinishedCouponMoney_comein = BigDecimal.ZERO;
        BigDecimal orderBusyCouponMoney_comein = BigDecimal.ZERO;
        BigDecimal orderTotalCouponMoney = BigDecimal.ZERO;

        orderFinishedCouponMoney_this = orderFinishedInfoMapper
            .sumCouponMoneyByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedCouponMoney_this) {
            orderFinishedCouponMoney_this = BigDecimal.ZERO;
        }
        orderFinishedCouponMoney_getout = orderFinishedInfoMapper
            .sumCouponMoneyGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedCouponMoney_getout) {
            orderFinishedCouponMoney_getout = BigDecimal.ZERO;
        }
        orderFinishedCouponMoney_comein = orderFinishedInfoMapper
            .sumCouponMoneyComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedCouponMoney_comein) {
            orderFinishedCouponMoney_comein = BigDecimal.ZERO;
        }
        orderTotalCouponMoney = orderFinishedCouponMoney_this.add(orderFinishedCouponMoney_getout)
            .add(orderFinishedCouponMoney_comein);

        map.put("orderFinishedCouponMoney_this",
            orderFinishedCouponMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyCouponMoney_this",
            orderBusyCouponMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedCouponMoney_getout",
            orderFinishedCouponMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyCouponMoney_getout",
            orderBusyCouponMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledCouponMoney",
            orderCanceledCouponMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedCouponMoney_comein",
            orderFinishedCouponMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyCouponMoney_comein",
            orderBusyCouponMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalCouponMoney",
            orderTotalCouponMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup4
        BigDecimal orderFinishedPayMoney_this = BigDecimal.ZERO;
        BigDecimal orderBusyPayMoney_this = BigDecimal.ZERO;
        BigDecimal orderFinishedPayMoney_getout = BigDecimal.ZERO;
        BigDecimal orderBusyPayMoney_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledPayMoney = BigDecimal.ZERO;
        BigDecimal orderFinishedPayMoney_comein = BigDecimal.ZERO;
        BigDecimal orderBusyPayMoney_comein = BigDecimal.ZERO;
        BigDecimal orderTotalPayMoney = BigDecimal.ZERO;

        orderFinishedPayMoney_this = orderFinishedInfoMapper
            .sumPayMoneyByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedPayMoney_this) {
            orderFinishedPayMoney_this = BigDecimal.ZERO;
        }
        orderFinishedPayMoney_getout = orderFinishedInfoMapper
            .sumPayMoneyGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedPayMoney_getout) {
            orderFinishedPayMoney_getout = BigDecimal.ZERO;
        }
        orderFinishedPayMoney_comein = orderFinishedInfoMapper
            .sumPayMoneyComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedPayMoney_comein) {
            orderFinishedPayMoney_comein = BigDecimal.ZERO;
        }
        orderTotalPayMoney = orderFinishedPayMoney_this.add(orderFinishedPayMoney_getout)
            .add(orderFinishedPayMoney_comein);

        map.put("orderFinishedPayMoney_this",
            orderFinishedPayMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyPayMoney_this",
            orderBusyPayMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedPayMoney_getout",
            orderFinishedPayMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyPayMoney_getout",
            orderBusyPayMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledPayMoney",
            orderCanceledPayMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedPayMoney_comein",
            orderFinishedPayMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyPayMoney_comein",
            orderBusyPayMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalPayMoney",
            orderTotalPayMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup5
        BigDecimal orderFinishedCompanyMoney_this = BigDecimal.ZERO;
        BigDecimal orderBusyCompanyMoney_this = BigDecimal.ZERO;
        BigDecimal orderFinishedCompanyMoney_getout = BigDecimal.ZERO;
        BigDecimal orderBusyCompanyMoney_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledCompanyMoney = BigDecimal.ZERO;
        BigDecimal orderFinishedCompanyMoney_comein = BigDecimal.ZERO;
        BigDecimal orderBusyCompanyMoney_comein = BigDecimal.ZERO;
        BigDecimal orderTotalCompanyMoney = BigDecimal.ZERO;

        orderFinishedCompanyMoney_this = orderFinishedInfoMapper
            .sumCompanyMoneyByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedCompanyMoney_this) {
            orderFinishedCompanyMoney_this = BigDecimal.ZERO;
        }
        orderFinishedCompanyMoney_getout = orderFinishedInfoMapper
            .sumCompanyMoneyGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedCompanyMoney_getout) {
            orderFinishedCompanyMoney_getout = BigDecimal.ZERO;
        }
        orderFinishedCompanyMoney_comein = orderFinishedInfoMapper
            .sumCompanyMoneyComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedCompanyMoney_comein) {
            orderFinishedCompanyMoney_comein = BigDecimal.ZERO;
        }
        orderTotalCompanyMoney = orderFinishedCompanyMoney_this
            .add(orderFinishedCompanyMoney_getout).add(orderFinishedCompanyMoney_comein);

        map.put("orderFinishedCompanyMoney_this",
            orderFinishedCompanyMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyCompanyMoney_this",
            orderBusyCompanyMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedCompanyMoney_getout", orderFinishedCompanyMoney_getout);
        map.put("orderBusyCompanyMoney_getout",
            orderBusyCompanyMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledCompanyMoney",
            orderCanceledCompanyMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedCompanyMoney_comein",
            orderFinishedCompanyMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyCompanyMoney_comein",
            orderBusyCompanyMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalCompanyMoney",
            orderTotalCompanyMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup6
        BigDecimal orderFinishedDriverMoney_this = BigDecimal.ZERO;
        BigDecimal orderBusyDriverMoney_this = BigDecimal.ZERO;
        BigDecimal orderFinishedDriverMoney_getout = BigDecimal.ZERO;
        BigDecimal orderBusyDriverMoney_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledDriverMoney = BigDecimal.ZERO;
        BigDecimal orderFinishedDriverMoney_comein = BigDecimal.ZERO;
        BigDecimal orderBusyDriverMoney_comein = BigDecimal.ZERO;
        BigDecimal orderTotalDriverMoney = BigDecimal.ZERO;

        orderFinishedDriverMoney_this = orderFinishedInfoMapper
            .sumDriverMoneyByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedDriverMoney_this) {
            orderFinishedDriverMoney_this = BigDecimal.ZERO;
        }
        orderFinishedDriverMoney_getout = orderFinishedInfoMapper
            .sumDriverMoneyGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedDriverMoney_getout) {
            orderFinishedDriverMoney_getout = BigDecimal.ZERO;
        }
        orderFinishedDriverMoney_comein = orderFinishedInfoMapper
            .sumDriverMoneyComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedDriverMoney_comein) {
            orderFinishedDriverMoney_comein = BigDecimal.ZERO;
        }
        orderTotalDriverMoney = orderFinishedDriverMoney_this.add(orderFinishedDriverMoney_getout)
            .add(orderFinishedDriverMoney_comein);

        map.put("orderFinishedDriverMoney_this",
            orderFinishedDriverMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyDriverMoney_this",
            orderBusyDriverMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedDriverMoney_getout",
            orderFinishedDriverMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyDriverMoney_getout",
            orderBusyDriverMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledDriverMoney",
            orderCanceledDriverMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedDriverMoney_comein",
            orderFinishedDriverMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyDriverMoney_comein",
            orderBusyDriverMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalDriverMoney",
            orderTotalDriverMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup7.1 infofee
        BigDecimal orderFinishedInfofee_this = BigDecimal.ZERO;
        BigDecimal orderBusyInfofee_this = BigDecimal.ZERO;
        BigDecimal orderFinishedInfofee_getout = BigDecimal.ZERO;
        BigDecimal orderBusyInfofee_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledInfofee = BigDecimal.ZERO;
        BigDecimal orderFinishedInfofee_comein = BigDecimal.ZERO;
        BigDecimal orderBusyInfofee_comein = BigDecimal.ZERO;
        BigDecimal orderTotalInfofee = BigDecimal.ZERO;

        orderFinishedInfofee_this = orderFinishedInfoMapper
            .sumInfofeeByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedInfofee_this) {
            orderFinishedInfofee_this = BigDecimal.ZERO;
        }
        orderFinishedInfofee_getout = orderFinishedInfoMapper
            .sumInfofeeGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedInfofee_getout) {
            orderFinishedInfofee_getout = BigDecimal.ZERO;
        }
        orderFinishedInfofee_comein = orderFinishedInfoMapper
            .sumInfofeeComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedInfofee_comein) {
            orderFinishedInfofee_comein = BigDecimal.ZERO;
        }
        orderTotalInfofee = orderFinishedInfofee_this.add(orderFinishedInfofee_getout)
            .add(orderFinishedInfofee_comein);

        map.put("orderFinishedInfofee_this",
            orderFinishedInfofee_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyInfofee_this",
            orderBusyInfofee_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedInfofee_getout",
            orderFinishedInfofee_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyInfofee_getout",
            orderBusyInfofee_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledInfofee",
            orderCanceledInfofee.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedInfofee_comein",
            orderFinishedInfofee_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyInfofee_comein",
            orderBusyInfofee_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalInfofee",
            orderTotalInfofee.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup7.2 djxfee
        BigDecimal orderFinishedDjxfee_this = BigDecimal.ZERO;
        BigDecimal orderBusyDjxfee_this = BigDecimal.ZERO;
        BigDecimal orderFinishedDjxfee_getout = BigDecimal.ZERO;
        BigDecimal orderBusyDjxfee_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledDjxfee = BigDecimal.ZERO;
        BigDecimal orderFinishedDjxfee_comein = BigDecimal.ZERO;
        BigDecimal orderBusyDjxfee_comein = BigDecimal.ZERO;
        BigDecimal orderTotalDjxfee = BigDecimal.ZERO;

        orderFinishedDjxfee_this = orderFinishedInfoMapper
            .sumDjxfeeByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedDjxfee_this) {
            orderFinishedDjxfee_this = BigDecimal.ZERO;
        }
        orderFinishedDjxfee_getout = orderFinishedInfoMapper
            .sumDjxfeeGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedDjxfee_getout) {
            orderFinishedDjxfee_getout = BigDecimal.ZERO;
        }
        orderFinishedDjxfee_comein = orderFinishedInfoMapper
            .sumDjxfeeComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedDjxfee_comein) {
            orderFinishedDjxfee_comein = BigDecimal.ZERO;
        }
        orderTotalDjxfee = orderFinishedDjxfee_this.add(orderFinishedDjxfee_getout)
            .add(orderFinishedDjxfee_comein);

        map.put("orderFinishedDjxfee_this",
            orderFinishedDjxfee_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyDjxfee_this",
            orderBusyDjxfee_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedDjxfee_getout",
            orderFinishedDjxfee_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyDjxfee_getout",
            orderBusyDjxfee_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledDjxfee",
            orderCanceledDjxfee.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedDjxfee_comein",
            orderFinishedDjxfee_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyDjxfee_comein",
            orderBusyDjxfee_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalDjxfee",
            orderTotalDjxfee.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup7.3 ywxfee
        BigDecimal orderFinishedYwxfee_this = BigDecimal.ZERO;
        BigDecimal orderBusyYwxfee_this = BigDecimal.ZERO;
        BigDecimal orderFinishedYwxfee_getout = BigDecimal.ZERO;
        BigDecimal orderBusyYwxfee_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledYwxfee = BigDecimal.ZERO;
        BigDecimal orderFinishedYwxfee_comein = BigDecimal.ZERO;
        BigDecimal orderBusyYwxfee_comein = BigDecimal.ZERO;
        BigDecimal orderTotalYwxfee = BigDecimal.ZERO;

        orderFinishedYwxfee_this = orderFinishedInfoMapper
            .sumYwxfeeByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedYwxfee_this) {
            orderFinishedYwxfee_this = BigDecimal.ZERO;
        }
        orderFinishedYwxfee_getout = orderFinishedInfoMapper
            .sumYwxfeeGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedYwxfee_getout) {
            orderFinishedYwxfee_getout = BigDecimal.ZERO;
        }
        orderFinishedYwxfee_comein = orderFinishedInfoMapper
            .sumYwxfeeComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedYwxfee_comein) {
            orderFinishedYwxfee_comein = BigDecimal.ZERO;
        }
        orderTotalYwxfee = orderFinishedYwxfee_this.add(orderFinishedYwxfee_getout)
            .add(orderFinishedYwxfee_comein);

        map.put("orderFinishedYwxfee_this",
            orderFinishedYwxfee_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyYwxfee_this",
            orderBusyYwxfee_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedYwxfee_getout",
            orderFinishedYwxfee_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyYwxfee_getout",
            orderBusyYwxfee_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledYwxfee",
            orderCanceledYwxfee.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedYwxfee_comein",
            orderFinishedYwxfee_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyYwxfee_comein",
            orderBusyYwxfee_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalYwxfee",
            orderTotalYwxfee.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup8
        BigDecimal orderFinishedManagerMoney_this = BigDecimal.ZERO;
        BigDecimal orderBusyManagerMoney_this = BigDecimal.ZERO;
        BigDecimal orderFinishedManagerMoney_getout = BigDecimal.ZERO;
        BigDecimal orderBusyManagerMoney_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledManagerMoney = BigDecimal.ZERO;
        BigDecimal orderFinishedManagerMoney_comein = BigDecimal.ZERO;
        BigDecimal orderBusyManagerMoney_comein = BigDecimal.ZERO;
        BigDecimal orderTotalManagerMoney = BigDecimal.ZERO;

        orderFinishedManagerMoney_this = orderFinishedInfoMapper
            .sumManagerMoneyByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedManagerMoney_this) {
            orderFinishedManagerMoney_this = BigDecimal.ZERO;
        }
        orderFinishedManagerMoney_getout = orderFinishedInfoMapper
            .sumManagerMoneyGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedManagerMoney_getout) {
            orderFinishedManagerMoney_getout = BigDecimal.ZERO;
        }
        orderFinishedManagerMoney_comein = orderFinishedInfoMapper
            .sumManagerMoneyComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedManagerMoney_comein) {
            orderFinishedManagerMoney_comein = BigDecimal.ZERO;
        }
        orderTotalManagerMoney = orderFinishedManagerMoney_this
            .add(orderFinishedManagerMoney_getout).add(orderFinishedManagerMoney_comein);

        map.put("orderFinishedManagerMoney_this",
            orderFinishedManagerMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyManagerMoney_this",
            orderBusyManagerMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedManagerMoney_getout",
            orderFinishedManagerMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyManagerMoney_getout",
            orderBusyManagerMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledManagerMoney",
            orderCanceledManagerMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedManagerMoney_comein",
            orderFinishedManagerMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyManagerMoney_comein",
            orderBusyManagerMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalManagerMoney",
            orderTotalManagerMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        //setup9
        BigDecimal orderFinishedRebateMoney_this = BigDecimal.ZERO;
        BigDecimal orderBusyRebateMoney_this = BigDecimal.ZERO;
        BigDecimal orderFinishedRebateMoney_getout = BigDecimal.ZERO;
        BigDecimal orderBusyRebateMoney_getout = BigDecimal.ZERO;
        BigDecimal orderCanceledRebateMoney = BigDecimal.ZERO;
        BigDecimal orderFinishedRebateMoney_comein = BigDecimal.ZERO;
        BigDecimal orderBusyRebateMoney_comein = BigDecimal.ZERO;
        BigDecimal orderTotalRebateMoney = BigDecimal.ZERO;

        orderFinishedRebateMoney_this = orderFinishedInfoMapper
            .sumRebateMoneyByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedRebateMoney_this) {
            orderFinishedRebateMoney_this = BigDecimal.ZERO;
        }
        orderFinishedRebateMoney_getout = orderFinishedInfoMapper
            .sumRebateMoneyGetoutByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedRebateMoney_getout) {
            orderFinishedRebateMoney_getout = BigDecimal.ZERO;
        }
        orderFinishedRebateMoney_comein = orderFinishedInfoMapper
            .sumRebateMoneyComeInByCompanyWithDate(companyId, start, end);
        if (null == orderFinishedRebateMoney_comein) {
            orderFinishedRebateMoney_comein = BigDecimal.ZERO;
        }
        orderTotalRebateMoney = orderFinishedRebateMoney_this.add(orderFinishedRebateMoney_getout)
            .add(orderFinishedRebateMoney_comein);

        map.put("orderFinishedRebateMoney_this",
            orderFinishedRebateMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyRebateMoney_this",
            orderBusyRebateMoney_this.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedRebateMoney_getout",
            orderFinishedRebateMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyRebateMoney_getout",
            orderBusyRebateMoney_getout.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderCanceledRebateMoney",
            orderCanceledRebateMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderFinishedRebateMoney_comein",
            orderFinishedRebateMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderBusyRebateMoney_comein",
            orderBusyRebateMoney_comein.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
        map.put("orderTotalRebateMoney",
            orderTotalRebateMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

        if (principal.isCompanyType()) {

            map.put("totalAmount", orderMapper.countAllByCompanyWithDate(null, start, end));
//			map.put("totalAmount", orderMapper.countByCompanyWithStatusAndDate(null, null, null, start, end));
            map.put("totalCancelAmount", orderMapper
                .countByCompanyWithStatusAndDate(null, Order.ORDER_STATUS_CANCELED, null, start,
                    end));

            map.put("totalRealCash",
                orderFinishedInfoMapper.sumAllRealCashByCompanyWithDate(null, start, end));
            map.put("totalCouponMoney",
                orderFinishedInfoMapper.sumAllCouponMoneyByCompanyWithDate(null, start, end));
            map.put("totalPayMoney",
                orderFinishedInfoMapper.sumAllPayMoneyByCompanyWithDate(null, start, end));
            map.put("totalCompanyMoney",
                orderFinishedInfoMapper.sumAllCompanyMoneyByCompanyWithDate(null, start, end));
            map.put("totalDriverMoney",
                orderFinishedInfoMapper.sumAllDriverMoneyByCompanyWithDate(null, start, end));
            map.put("totalManagerMoney",
                orderFinishedInfoMapper.sumAllManagerMoneyByCompanyWithDate(null, start, end));
            map.put("totalInfofee",
                orderFinishedInfoMapper.sumAllInfofeeByCompanyWithDate(null, start, end));
            map.put("totalRebateMoney",
                orderFinishedInfoMapper.sumAllRebateMoneyByCompanyWithDate(null, start, end));

            map.put("totalGuoluMoney",
                orderMapper.sumAllGuoluMoneyByCompanyWithDate(null, start, end));

        }

        return map;
    }

    @Override
    public Map<String, Object> paotuiCompositive(Long companyId, Date start, Date end) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        Long orderFinishedAmount_this;//本公司单并且是本公司司机完成单量
        Long orderBusyAmount_this;//本公司单并且是本公司司机执行中单量（包括预派单）
        Long orderFinishedAmount_getout;//本公司单并且是其他公司司机完成单量
        Long orderBusyAmount_getout;//本公司单并且是其他公司司机执行中单量（包括预派单）
        Long orderCanceledAmount;//本公司订单销单量
        Long orderFinishedAmount_comein;//其他公司单并且是本公司司机完成单量
        Long orderBusyAmount_comein;//其他公司单并且是本公司司机执行中单量（包括预派单）
        Long orderTotalAmount = 0L;//总单量

        Double orderFinishedMoney_this = 0d;
        Double orderFinishedMoney_getout = 0d;
        Double orderFinishedMoney_comein = 0d;
        Double orderTotalMoney = 0d;

        Double orderFinishedCompanyMoney_this = 0d;
        Double orderFinishedCompanyMoney_getout = 0d;
        Double orderFinishedCompanyMoney_comein = 0d;
        Double orderTotalCompanyMoney = 0d;

        Double orderFinishedDriverMoney_this = 0d;
        Double orderFinishedDriverMoney_getout = 0d;
        Double orderFinishedDriverMoney_comein = 0d;
        Double orderTotalDriverMoney = 0d;
        Double totalGuoluMoney = 0d;
        Map<String, Object> map = new HashMap<String, Object>();

        StringBuilder sb = new StringBuilder();
        sb.append(errandApi.getErrandBaseURL() + ErrandApi.COMPOSITIVE + "?appKey={appKey}");

        Map<String, String> kv = new HashMap<String, String>();

        kv.put("companyId", String.valueOf(companyId));
        sb.append("&companyId={companyId}");

        if (null != start) {
            kv.put("start", String.valueOf(start.getTime()));
            sb.append("&start={start}");
        }
        if (null != end) {
            kv.put("end", String.valueOf(end.getTime()));
            sb.append("&end={end}");
        }

        if (principal.isCompanyType()) {
            kv.put("maincompany", Boolean.TRUE.toString());
            sb.append("&maincompany={maincompany}");
        } else {
            kv.put("maincompany", Boolean.FALSE.toString());
            sb.append("&maincompany={maincompany}");
        }

        String result = errandApi.get(sb.toString(), kv, settingUtils.get());

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");

                orderFinishedAmount_this = data.getLong("orderNumber");
                orderBusyAmount_this = data.getLong("runOrderNumber");
                orderFinishedAmount_getout = data.getLong("otherOrderNumber");
                orderBusyAmount_getout = data.getLong("runOtherOrderNumber");
                orderCanceledAmount = data.getLong("cancelOrderNumber");
                orderFinishedAmount_comein = data.getLong("inOrderNumber");
                orderBusyAmount_comein = data.getLong("inRunOrderNumber");
                orderTotalAmount = data.getLong("sumOrderNumber");
                map.put("orderFinishedAmount_this", orderFinishedAmount_this);
                map.put("orderBusyAmount_this", orderBusyAmount_this);
                map.put("orderFinishedAmount_getout", orderFinishedAmount_getout);
                map.put("orderBusyAmount_getout", orderBusyAmount_getout);
                map.put("orderCanceledAmount", orderCanceledAmount);
                map.put("orderFinishedAmount_comein", orderFinishedAmount_comein);
                map.put("orderBusyAmount_comein", orderBusyAmount_comein);
                map.put("orderTotalAmount", orderTotalAmount);

                orderFinishedMoney_this = data.getDouble("orderRealCash");
                orderFinishedMoney_getout = data.getDouble("otherOrderRealCash");
                orderFinishedMoney_comein = data.getDouble("inOrderRealCash");
                orderTotalMoney = data.getDouble("sumOrderRealCash");
                map.put("orderFinishedMoney_this",
                    new BigDecimal(orderFinishedMoney_this).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedMoney_getout",
                    new BigDecimal(orderFinishedMoney_getout).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedMoney_comein",
                    new BigDecimal(orderFinishedMoney_comein).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderTotalMoney",
                    new BigDecimal(orderTotalMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderFinishedCompanyMoney_this = data.getDouble("companyProfit");
                orderFinishedCompanyMoney_getout = data.getDouble("otherCompanyProfit");
                orderFinishedCompanyMoney_comein = data.getDouble("inCompanyProfit");
                orderTotalCompanyMoney = data.getDouble("sumCompanyProfit");
                map.put("orderFinishedCompanyMoney_this",
                    new BigDecimal(orderFinishedCompanyMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCompanyMoney_getout",
                    new BigDecimal(orderFinishedCompanyMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCompanyMoney_comein",
                    new BigDecimal(orderFinishedCompanyMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalCompanyMoney",
                    new BigDecimal(orderTotalCompanyMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderFinishedDriverMoney_this = data.getDouble("driverProfit");
                orderFinishedDriverMoney_getout = data.getDouble("otherDriverProfit");
                orderFinishedDriverMoney_comein = data.getDouble("inDriverProfit");
                orderTotalDriverMoney = data.getDouble("sumDriverProfit");
                map.put("orderFinishedDriverMoney_this",
                    new BigDecimal(orderFinishedDriverMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedDriverMoney_getout",
                    new BigDecimal(orderFinishedDriverMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedDriverMoney_comein",
                    new BigDecimal(orderFinishedDriverMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalDriverMoney",
                    new BigDecimal(orderTotalDriverMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                if (principal.isCompanyType()) {
                    map.put("totalGuoluMoney", new BigDecimal(data.getDouble("totalGuoluMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalAmount", new BigDecimal(data.getDouble("totalAmount"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCancelAmount", new BigDecimal(data.getDouble("totalCancelAmount"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalRealCash", new BigDecimal(data.getDouble("totalRealCash"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalPayMoney", new BigDecimal(data.getDouble("totalPayMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCompanyMoney",
                        new BigDecimal(data.getDouble("totalCompanyProfit"))
                            .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalDriverMoney", new BigDecimal(data.getDouble("totalDriverProfit"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCouponMoney", new BigDecimal(data.getDouble("totalCouponMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                }

            }
        }

        return map;
    }

    @Override
    public Map<String, Object> zhuanCompositive(Long companyId, Date start, Date end) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();
        DecimalFormat df = new DecimalFormat("######0.00");
        Long orderFinishedAmount_this;//本公司单并且是本公司司机完成单量
        Long orderBusyAmount_this;//本公司单并且是本公司司机执行中单量（包括预派单）
        Long orderFinishedAmount_getout;//本公司单并且是其他公司司机完成单量
        Long orderBusyAmount_getout;//本公司单并且是其他公司司机执行中单量（包括预派单）
        Long orderCanceledAmount;//本公司订单销单量
        Long orderFinishedAmount_comein;//其他公司单并且是本公司司机完成单量
        Long orderBusyAmount_comein;//其他公司单并且是本公司司机执行中单量（包括预派单）
        Long orderTotalAmount = 0L;//总单量

        Double orderTotalCouponMoney = 0d;
        Double totalGuoluMoney = 0d;//过路费
        Double orderFinishedCouponMoney_this = 0d;//由本公司司机完成订单优惠券金额;
        Double orderFinishedCouponMoney_getout = 0d;//由平台其它公司司机完成订单优惠券金额;
        Double orderFinishedCouponMoney_comein = 0d;//平台其它公司创建、由本公司司机完成的订单优惠券金额;

        Double orderFinishedMoney_this = 0d;
        Double orderFinishedMoney_getout = 0d;
        Double orderFinishedMoney_comein = 0d;
        Double orderTotalMoney = 0d;

        Double orderFinishedPayMoney_this = 0.0;
        Double orderFinishedPayMoney_getout = 0.0;
        Double orderFinishedPayMoney_comein = 0.0;
        Double orderTotalPayMoney = 0.0;

        Double orderFinishedCompanyMoney_this = 0d;
        Double orderFinishedCompanyMoney_getout = 0d;
        Double orderFinishedCompanyMoney_comein = 0d;
        Double orderTotalCompanyMoney = 0d;

        Double orderFinishedDriverMoney_this = 0d;
        Double orderFinishedDriverMoney_getout = 0d;
        Double orderFinishedDriverMoney_comein = 0d;
        Double orderTotalDriverMoney = 0d;

        Map<String, Object> map = new HashMap<String, Object>();

        StringBuilder sb = new StringBuilder();
        sb.append(zhuanApi.getZhuanBaseURL() + ZhuanApi.COMPOSITIVE + "?appKey={appKey}");

        Map<String, String> kv = new HashMap<String, String>();

        kv.put("companyId", String.valueOf(companyId));
        sb.append("&companyId={companyId}");

        if (null != start) {
            kv.put("start", String.valueOf(start.getTime()));
            sb.append("&start={start}");
        }
        if (null != end) {
            kv.put("end", String.valueOf(end.getTime()));
            sb.append("&end={end}");
        }

        if (principal.isCompanyType()) {
            kv.put("maincompany", Boolean.TRUE.toString());
            sb.append("&maincompany={maincompany}");
        } else {
            kv.put("maincompany", Boolean.FALSE.toString());
            sb.append("&maincompany={maincompany}");
        }

        String result = zhuanApi.get(sb.toString(), kv, settingUtils.get());

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");

                orderFinishedAmount_this = data.getLong("orderNumber");
                orderBusyAmount_this = data.getLong("runOrderNumber");
                orderFinishedAmount_getout = data.getLong("otherOrderNumber");
                orderBusyAmount_getout = data.getLong("runOtherOrderNumber");
                orderCanceledAmount = data.getLong("cancelOrderNumber");
                orderFinishedAmount_comein = data.getLong("inOrderNumber");
                orderBusyAmount_comein = data.getLong("inRunOrderNumber");
                orderTotalAmount = data.getLong("sumOrderNumber");
                map.put("orderFinishedAmount_this", orderFinishedAmount_this);
                map.put("orderBusyAmount_this", orderBusyAmount_this);
                map.put("orderFinishedAmount_getout", orderFinishedAmount_getout);
                map.put("orderBusyAmount_getout", orderBusyAmount_getout);
                map.put("orderCanceledAmount", orderCanceledAmount);
                map.put("orderFinishedAmount_comein", orderFinishedAmount_comein);
                map.put("orderBusyAmount_comein", orderBusyAmount_comein);
                map.put("orderTotalAmount", orderTotalAmount);

                orderFinishedMoney_this = data.getDouble("orderRealCash");
                orderFinishedMoney_getout = data.getDouble("otherOrderRealCash");
                orderFinishedMoney_comein = data.getDouble("inOrderRealCash");
                orderTotalMoney = data.getDouble("sumOrderRealCash");

                orderFinishedPayMoney_this = data.optDouble("orderFinishedPayMoney_this", 0.0);
                orderFinishedPayMoney_getout = data.optDouble("orderFinishedPayMoney_getout", 0.0);
                orderFinishedPayMoney_comein = data.optDouble("orderFinishedPayMoney_comein", 0.0);
                orderTotalPayMoney = data.optDouble("orderTotalPayMoney", 0.0);

                map.put("orderFinishedMoney_this",
                    new BigDecimal(orderFinishedMoney_this).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedPayMoney_this",
                    new BigDecimal(orderFinishedPayMoney_this).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedMoney_getout",
                    new BigDecimal(orderFinishedMoney_getout).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedPayMoney_getout", new BigDecimal(orderFinishedPayMoney_getout)
                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedMoney_comein",
                    new BigDecimal(orderFinishedMoney_comein).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedPayMoney_comein", new BigDecimal(orderFinishedPayMoney_comein)
                    .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalMoney",
                    new BigDecimal(orderTotalMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderTotalPayMoney",
                    new BigDecimal(orderTotalPayMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderFinishedCompanyMoney_this = data.getDouble("companyProfit");
                orderFinishedCompanyMoney_getout = data.getDouble("otherCompanyProfit");
                orderFinishedCompanyMoney_comein = data.getDouble("inCompanyProfit");
                orderTotalCompanyMoney = data.getDouble("sumCompanyProfit");
                map.put("orderFinishedCompanyMoney_this",
                    new BigDecimal(orderFinishedCompanyMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCompanyMoney_getout",
                    new BigDecimal(orderFinishedCompanyMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCompanyMoney_comein",
                    new BigDecimal(orderFinishedCompanyMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalCompanyMoney",
                    new BigDecimal(orderTotalCompanyMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderFinishedDriverMoney_this = data.getDouble("driverProfit");
                orderFinishedDriverMoney_getout = data.getDouble("otherDriverProfit");
                orderFinishedDriverMoney_comein = data.getDouble("inDriverProfit");
                orderTotalDriverMoney = data.getDouble("sumDriverProfit");
                map.put("orderFinishedDriverMoney_this",
                    new BigDecimal(orderFinishedDriverMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedDriverMoney_getout",
                    new BigDecimal(orderFinishedDriverMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedDriverMoney_comein",
                    new BigDecimal(orderFinishedDriverMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalDriverMoney",
                    new BigDecimal(orderTotalDriverMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderTotalCouponMoney = data.getDouble("orderTotalCouponMoney");
                orderFinishedCouponMoney_this = data.getDouble("orderFinishedCouponMoney_this");
                orderFinishedCouponMoney_getout = data.getDouble("orderFinishedCouponMoney_getout");
                orderFinishedCouponMoney_comein = data.getDouble("orderFinishedCouponMoney_comein");
                map.put("orderTotalCouponMoney",
                    new BigDecimal(orderTotalCouponMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedCouponMoney_this",
                    new BigDecimal(orderFinishedCouponMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCouponMoney_getout",
                    new BigDecimal(orderFinishedCouponMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCouponMoney_comein",
                    new BigDecimal(orderFinishedCouponMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                if (principal.isCompanyType()) {
                    map.put("totalAmount", new BigDecimal(data.getDouble("totalAmount"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalGuoluMoney", new BigDecimal(data.getDouble("totalGuoluMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCancelAmount", new BigDecimal(data.getDouble("totalCancelAmount"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalRealCash", new BigDecimal(data.getDouble("totalRealCash"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalPayMoney", new BigDecimal(data.getDouble("totalPayMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCompanyMoney",
                        new BigDecimal(data.getDouble("totalCompanyProfit"))
                            .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalDriverMoney", new BigDecimal(data.getDouble("totalDriverProfit"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCouponMoney", new BigDecimal(data.getDouble("totalCouponMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                }

            }
        }

        return map;
    }

    /**
     * 货运订单汇总
     */
    @Override
    public Map<String, Object> freightCompositive(Long companyId, Date start, Date end) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();
        DecimalFormat df = new DecimalFormat("######0.00");
        Long orderFinishedAmount_this;//本公司单并且是本公司司机完成单量
        Long orderBusyAmount_this;//本公司单并且是本公司司机执行中单量（包括预派单）
        Long orderFinishedAmount_getout;//本公司单并且是其他公司司机完成单量
        Long orderBusyAmount_getout;//本公司单并且是其他公司司机执行中单量（包括预派单）
        Long orderCanceledAmount;//本公司订单销单量
        Long orderFinishedAmount_comein;//其他公司单并且是本公司司机完成单量
        Long orderBusyAmount_comein;//其他公司单并且是本公司司机执行中单量（包括预派单）
        Long orderTotalAmount = 0L;//总单量

        Double totalGuoluMoney = 0d;//所有过路费
        Double orderTotalCouponMoney = 0d;
        Double orderFinishedCouponMoney_this = 0d;//由本公司司机完成订单优惠券金额;
        Double orderFinishedCouponMoney_getout = 0d;//由平台其它公司司机完成订单优惠券金额;
        Double orderFinishedCouponMoney_comein = 0d;//平台其它公司创建、由本公司司机完成的订单优惠券金额;

        Double orderFinishedMoney_this = 0d;
        Double orderFinishedMoney_getout = 0d;
        Double orderFinishedMoney_comein = 0d;
        Double orderTotalMoney = 0d;

        Double orderFinishedCompanyMoney_this = 0d;
        Double orderFinishedCompanyMoney_getout = 0d;
        Double orderFinishedCompanyMoney_comein = 0d;
        Double orderTotalCompanyMoney = 0d;

        Double orderFinishedDriverMoney_this = 0d;
        Double orderFinishedDriverMoney_getout = 0d;
        Double orderFinishedDriverMoney_comein = 0d;
        Double orderTotalDriverMoney = 0d;

        Map<String, Object> map = new HashMap<String, Object>();

        StringBuilder sb = new StringBuilder();
        sb.append(freightApi.getFreightBaseURL() + FreightApi.COMPOSITIVE + "?appKey={appKey}");

        Map<String, String> kv = new HashMap<String, String>();

        kv.put("companyId", String.valueOf(companyId));
        sb.append("&companyId={companyId}");

        if (null != start) {
            kv.put("start", String.valueOf(start.getTime()));
            sb.append("&start={start}");
        }
        if (null != end) {
            kv.put("end", String.valueOf(end.getTime()));
            sb.append("&end={end}");
        }

        if (principal.isCompanyType()) {
            kv.put("maincompany", Boolean.TRUE.toString());
            sb.append("&maincompany={maincompany}");
        } else {
            kv.put("maincompany", Boolean.FALSE.toString());
            sb.append("&maincompany={maincompany}");
        }

        String result = errandApi.get(sb.toString(), kv, settingUtils.get());

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");

                orderFinishedAmount_this = data.getLong("orderNumber");
                orderBusyAmount_this = data.getLong("runOrderNumber");
                orderFinishedAmount_getout = data.getLong("otherOrderNumber");
                orderBusyAmount_getout = data.getLong("runOtherOrderNumber");
                orderCanceledAmount = data.getLong("cancelOrderNumber");
                orderFinishedAmount_comein = data.getLong("inOrderNumber");
                orderBusyAmount_comein = data.getLong("inRunOrderNumber");
                orderTotalAmount = data.getLong("sumOrderNumber");
                map.put("orderFinishedAmount_this", orderFinishedAmount_this);
                map.put("orderBusyAmount_this", orderBusyAmount_this);
                map.put("orderFinishedAmount_getout", orderFinishedAmount_getout);
                map.put("orderBusyAmount_getout", orderBusyAmount_getout);
                map.put("orderCanceledAmount", orderCanceledAmount);
                map.put("orderFinishedAmount_comein", orderFinishedAmount_comein);
                map.put("orderBusyAmount_comein", orderBusyAmount_comein);
                map.put("orderTotalAmount", orderTotalAmount);

                orderFinishedMoney_this = data.getDouble("orderRealCash");
                orderFinishedMoney_getout = data.getDouble("otherOrderRealCash");
                orderFinishedMoney_comein = data.getDouble("inOrderRealCash");
                orderTotalMoney = data.getDouble("sumOrderRealCash");

                map.put("orderFinishedMoney_this",
                    new BigDecimal(orderFinishedMoney_this).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedMoney_getout",
                    new BigDecimal(orderFinishedMoney_getout).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedMoney_comein",
                    new BigDecimal(orderFinishedMoney_comein).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderTotalMoney", orderTotalMoney);

                orderFinishedCompanyMoney_this = data.getDouble("companyProfit");
                orderFinishedCompanyMoney_getout = data.getDouble("otherCompanyProfit");
                orderFinishedCompanyMoney_comein = data.getDouble("inCompanyProfit");
                orderTotalCompanyMoney = data.getDouble("sumCompanyProfit");
                map.put("orderFinishedCompanyMoney_this",
                    new BigDecimal(orderFinishedCompanyMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCompanyMoney_getout",
                    new BigDecimal(orderFinishedCompanyMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCompanyMoney_comein",
                    new BigDecimal(orderFinishedCompanyMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalCompanyMoney",
                    new BigDecimal(orderTotalCompanyMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderFinishedDriverMoney_this = data.getDouble("driverProfit");
                orderFinishedDriverMoney_getout = data.getDouble("otherDriverProfit");
                orderFinishedDriverMoney_comein = data.getDouble("inDriverProfit");
                orderTotalDriverMoney = data.getDouble("sumDriverProfit");
                map.put("orderFinishedDriverMoney_this",
                    new BigDecimal(orderFinishedDriverMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedDriverMoney_getout",
                    new BigDecimal(orderFinishedDriverMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedDriverMoney_comein",
                    new BigDecimal(orderFinishedDriverMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalDriverMoney",
                    new BigDecimal(orderTotalDriverMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderTotalCouponMoney = data.getDouble("orderTotalCouponMoney");
                orderFinishedCouponMoney_this = data.getDouble("orderFinishedCouponMoney_this");
                orderFinishedCouponMoney_getout = data.getDouble("orderFinishedCouponMoney_getout");
                orderFinishedCouponMoney_comein = data.getDouble("orderFinishedCouponMoney_comein");

                map.put("orderTotalCouponMoney",
                    new BigDecimal(orderTotalCouponMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedCouponMoney_this",
                    new BigDecimal(orderFinishedCouponMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCouponMoney_getout",
                    new BigDecimal(orderFinishedCouponMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCouponMoney_comein",
                    new BigDecimal(orderFinishedCouponMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                if (principal.isCompanyType()) {
                    map.put("totalGuoluMoney", new BigDecimal(data.getDouble("totalGuoluMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalAmount", new BigDecimal(data.getDouble("totalAmount"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCancelAmount", new BigDecimal(data.getDouble("totalCancelAmount"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalRealCash", new BigDecimal(data.getDouble("totalRealCash"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalPayMoney", new BigDecimal(data.getDouble("totalPayMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCompanyMoney",
                        new BigDecimal(data.getDouble("totalCompanyProfit"))
                            .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalDriverMoney", new BigDecimal(data.getDouble("totalDriverProfit"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCouponMoney", new BigDecimal(data.getDouble("totalCouponMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                }

            }
        }

        return map;
    }

    @Override
    public List<List<String>> tableNewMemberMonth(Calendar calendar, Long companyId) {

        List<List<String>> dataList = new ArrayList<List<String>>();

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        StringBuilder sb = new StringBuilder();
        sb.append(passengerApi.getPassengerBaseURL() + PassengerApi.QUERY_ALL_PASSENGER_CHANNEL
            + "?appKey={appKey}&appId={appId}&sign={sign}");

        Map<String, String> kv = new HashMap<String, String>();

        String result = passengerApi.get(sb.toString(), kv, settingUtils.get());

        List<String> passengerGroups = new ArrayList<String>();

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONArray ja = jo.getJSONArray("data");
                Gson gson = new Gson();
                passengerGroups = gson.fromJson(ja.toString(), new TypeToken<List<String>>() {
                }.getType());
                if (!passengerGroups.contains("未知")) {
                    passengerGroups.add("未知");
                }
            }
        }

        for (String group : passengerGroups) {
            List<String> oneDataList = new ArrayList<String>();

            oneDataList.add(group);

            List<Passenger> thisYearMembers = new ArrayList<Passenger>();

            StringBuilder sb2 = new StringBuilder();
            sb2.append(passengerApi.getPassengerBaseURL() + PassengerApi.PASSENGER_CHANNEL
                + "?appKey={appKey}&appId={appId}&sign={sign}");
            sb2.append("&channel_name={channel_name}");
            sb2.append("&year={year}");

            Map<String, String> kv2 = new HashMap<String, String>();
            if (StringUtils.isEmpty(group)) {
                kv2.put("channel_name", String.valueOf("未知"));
            } else {
                kv2.put("channel_name", String.valueOf(group));
            }

            kv2.put("year", String.valueOf(calendar.get(Calendar.YEAR)));

            if (principal.isCompanyType()) {
                if (null != companyId) {
                    sb2.append("&companyId={companyId}");
                    kv2.put("companyId", String.valueOf(companyId));
                }
            } else {
                sb2.append("&companyId={companyId}");
                kv2.put("companyId", String.valueOf(principal.getCompanyId()));
            }

            String result2 = passengerApi.get(sb2.toString(), kv2, settingUtils.get());

            if (null != result2) {
                JSONObject jo = new JSONObject(result2);
                Integer code = jo.getInt("code");
                if (code == 0) {
                    JSONObject data = jo.getJSONObject("data");
                    JSONArray ja = data.getJSONArray("rows");
                    Gson gson = new Gson();
                    thisYearMembers = gson
                        .fromJson(ja.toString(), new TypeToken<List<Passenger>>() {
                        }.getType());
                }
            }

            for (int i = 1; i <= 12; i++) {
                Long amount = 0L;
                for (Passenger passenger : thisYearMembers) {
                    Calendar c = Calendar.getInstance();
                    try {
                        c.setTime(DateUtils.parseDate(passenger.getCreated(), "yyyy-MM-dd"));
                        int whichMonh = c.get(Calendar.MONTH) + 1;
                        if (whichMonh == i) {
                            amount += 1;
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                oneDataList.add(String.valueOf(amount));
            }

            dataList.add(oneDataList);

        }

        //总计
        List<String> oneDataList = new ArrayList<String>();
        oneDataList.add("总计");

        Long total1 = 0L;
        Long total2 = 0L;
        Long total3 = 0L;
        Long total4 = 0L;
        Long total5 = 0L;
        Long total6 = 0L;
        Long total7 = 0L;
        Long total8 = 0L;
        Long total9 = 0L;
        Long total10 = 0L;
        Long total11 = 0L;
        Long total12 = 0L;

        for (List<String> list : dataList) {
            total1 += Long.parseLong(list.get(1));
            total2 += Long.parseLong(list.get(2));
            total3 += Long.parseLong(list.get(3));
            total4 += Long.parseLong(list.get(4));
            total5 += Long.parseLong(list.get(5));
            total6 += Long.parseLong(list.get(6));
            total7 += Long.parseLong(list.get(7));
            total8 += Long.parseLong(list.get(8));
            total9 += Long.parseLong(list.get(9));
            total10 += Long.parseLong(list.get(10));
            total11 += Long.parseLong(list.get(11));
            total12 += Long.parseLong(list.get(12));
        }

        oneDataList.add(String.valueOf(total1));
        oneDataList.add(String.valueOf(total2));
        oneDataList.add(String.valueOf(total3));
        oneDataList.add(String.valueOf(total4));
        oneDataList.add(String.valueOf(total5));
        oneDataList.add(String.valueOf(total6));
        oneDataList.add(String.valueOf(total7));
        oneDataList.add(String.valueOf(total8));
        oneDataList.add(String.valueOf(total9));
        oneDataList.add(String.valueOf(total10));
        oneDataList.add(String.valueOf(total11));
        oneDataList.add(String.valueOf(total12));

        dataList.add(oneDataList);

        return dataList;
    }

    @Override
    public Long tableNewMemberMonthDetailCount(String fromSource, Integer year, Integer month,
        Long companyId) {

        if (fromSource.equals("总计")) {
            fromSource = null;
        }

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        StringBuilder sb = new StringBuilder();
        sb.append(passengerApi.getPassengerBaseURL() + PassengerApi.PASSENGER_CHANNEL
            + "?appKey={appKey}&appId={appId}&sign={sign}");

        Map<String, String> kv = new HashMap<String, String>();

        if (null != fromSource) {
            sb.append("&channel_name={channel_name}");
            kv.put("channel_name", String.valueOf(fromSource));
        }

        if (principal.isCompanyType()) {
            if (null != companyId) {
                sb.append("&companyId={companyId}");
                kv.put("companyId", String.valueOf(companyId));
            }
        } else {
            sb.append("&companyId={companyId}");
            kv.put("companyId", String.valueOf(principal.getCompanyId()));
        }

        if (null != year) {
            sb.append("&year={year}");
            kv.put("year", String.valueOf(year));
        }

        if (null != month) {
            sb.append("&month={month}");
            kv.put("month", String.valueOf(month));
        }

        String result = passengerApi.get(sb.toString(), kv, settingUtils.get());

        Long total = 0L;

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");
                total = data.getLong("total");
            }
        }

        return total;

    }

    @Override
    public PageVo<Passenger> tableNewMemberMonthDetailData(String fromSource,
        Integer year, Integer month, Long companyId) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        PageVo<Passenger> pages = new PageVo<Passenger>();

        Long totalElements = 0L;
        List<Passenger> passengerlist = new ArrayList<Passenger>();

        if (fromSource.equals("总计")) {
            fromSource = null;
        }

        StringBuilder sb = new StringBuilder();
        sb.append(passengerApi.getPassengerBaseURL() + PassengerApi.PASSENGER_CHANNEL
            + "?appKey={appKey}&appId={appId}&sign={sign}&page={page}&rows={rows}");

        Map<String, String> kv = new HashMap<String, String>();
        kv.put("page", String.valueOf(Pager.getPage() + 1));
        kv.put("rows", String.valueOf(Pager.getLimit()));

        if (principal.isCompanyType()) {
            if (null != companyId) {
                sb.append("&companyId={companyId}");
                kv.put("companyId", String.valueOf(companyId));
            }
        } else {
            sb.append("&companyId={companyId}");
            kv.put("companyId", String.valueOf(principal.getCompanyId()));
        }

        if (null != fromSource) {
            sb.append("&channel_name={channel_name}");
            kv.put("channel_name", String.valueOf(fromSource));
        }

        sb.append("&year={year}");
        sb.append("&month={month}");
        kv.put("year", String.valueOf(year));
        kv.put("month", String.valueOf(month));

        String result = passengerApi.get(sb.toString(), kv, settingUtils.get());

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");
                totalElements = data.getLong("total");
                JSONArray ja = data.getJSONArray("rows");
                Gson gson = new Gson();
                passengerlist = gson.fromJson(ja.toString(), new TypeToken<List<Passenger>>() {
                }.getType());
            }
        }

        pages.setContent(passengerlist);
        pages.setTotalElements(totalElements);

        return pages;
    }

    @Override
    public List<Passenger> exportTableNewMemberMonthDetail(String fromSource,
        Integer year, Integer month, Long companyId, boolean allAmount, Integer amounts) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        List<Passenger> passengerlist = new ArrayList<Passenger>();

        if (fromSource.equals("总计")) {
            fromSource = null;
        }

        StringBuilder sb = new StringBuilder();
        sb.append(passengerApi.getPassengerBaseURL() + PassengerApi.PASSENGER_CHANNEL
            + "?appKey={appKey}&appId={appId}&sign={sign}");

        Map<String, String> kv = new HashMap<String, String>();

        if (!principal.isCompanyType()) {
            if (allAmount) {
                sb.append("&companyId={companyId}");
                kv.put("companyId", String.valueOf(principal.getCompanyId()));
//				memberlist = memberMapper.selectNewMemberByCompanyAndYearMonthAndFromSource(principal.getCompanyId(),year,month,fromSource,null,null);
            } else {
                sb.append("&companyId={companyId}");
                sb.append("&page={page}");
                sb.append("&rows={rows}");
                kv.put("companyId", String.valueOf(principal.getCompanyId()));
                kv.put("page", String.valueOf(0));
                kv.put("rows", String.valueOf(amounts));
//				memberlist = memberMapper.selectNewMemberByCompanyAndYearMonthAndFromSource(principal.getCompanyId(),year,month,fromSource,0,amounts);
            }
        } else {
            if (null != companyId) {
                if (allAmount) {
                    sb.append("&companyId={companyId}");
                    kv.put("companyId", String.valueOf(companyId));
//					memberlist = memberMapper.selectNewMemberByCompanyAndYearMonthAndFromSource(companyId,year,month,fromSource,null,null);
                } else {
                    sb.append("&companyId={companyId}");
                    sb.append("&page={page}");
                    sb.append("&rows={rows}");
                    kv.put("companyId", String.valueOf(companyId));
                    kv.put("page", String.valueOf(0));
                    kv.put("rows", String.valueOf(amounts));
//					memberlist = memberMapper.selectNewMemberByCompanyAndYearMonthAndFromSource(companyId,year,month,fromSource,0,amounts);
                }
            } else {
                if (allAmount) {
//					memberlist = memberMapper.selectNewMemberByCompanyAndYearMonthAndFromSource(null,year,month,fromSource,null,null);
                } else {
                    sb.append("&page={page}");
                    sb.append("&rows={rows}");
                    kv.put("page", String.valueOf(0));
                    kv.put("rows", String.valueOf(amounts));
//					memberlist = memberMapper.selectNewMemberByCompanyAndYearMonthAndFromSource(null,year,month,fromSource,0,amounts);
                }
            }
        }

        if (null != fromSource) {
            sb.append("&channel_name={channel_name}");
            kv.put("channel_name", String.valueOf(fromSource));
        }

        sb.append("&year={year}");
        sb.append("&month={month}");
        kv.put("year", String.valueOf(year));
        kv.put("month", String.valueOf(month));

        String result = passengerApi.get(sb.toString(), kv, settingUtils.get());

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");
                JSONArray ja = data.getJSONArray("rows");
                Gson gson = new Gson();
                passengerlist = gson.fromJson(ja.toString(), new TypeToken<List<Passenger>>() {
                }.getType());
            }
        }

        return passengerlist;
    }

    @Override
    public PageVo<DirverStatistics> driverOrder(Date start, Date end, Long companyId, String name,
        Integer offset, Integer size) {
        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        Map<String, Object> params = new HashMap<String, Object>();
        if (null != offset) {
            params.put("offset", offset);
        }
        if (null != size) {
            params.put("size", size);
        }

        if (!principal.isCompanyType()) {
            params.put("companyId", principal.getCompanyId());
        } else {
            if (companyId != null) {
                params.put("companyId", companyId);
            }
        }

        if (!StringUtils.isEmpty(name)) {
            params.put("name", "%" + name + "%");
        }

        List<Driver> content = driverMapper.selectByPage(params);
//        List<Driver> drivers = null;
//        if (principal.isCompanyType()) {
//            drivers = driverMapper.selectAll();
//        } else {
//            drivers = driverMapper.selectAllByCompany(principal.getCompanyId());
//        }

//        DirverStatistics count2 = new DirverStatistics();
//        count2.setName("总计");

        ServiceSetting serviceSetting = ServiceUtil.checkOpen();

//        if (serviceSetting.isDaijia()) {
//            for (Driver driver : drivers) {
//
//                List<Order> orderlist = orderMapper.selectFinishedByDriverWithDate(driver.getId(), start, end, null, null);
//
//                // 订单数 订单接
//                if (!CollectionUtils.isEmpty(orderlist)) {
//                    for (Order order : orderlist) {
//                        count2.setDaijiaMoney(count2.getDaijiaMoney().add(order.getRealCash()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                    }
//                    count2.setDaijiaFinishNums(count2.getDaijiaFinishNums() + orderlist.size());
//                }
//
//                // 提成
//                List<DriverPaymentsRecord> recordlist = driverPaymentsRecordMapper.selectByRecordTypeAndDriver(DriverPaymentsRecord.RECHARGE_TYPE_ORDER, driver.getId(), DriverPaymentsRecord.ORDER_TYPE_DAIJIA, start, end);
//                if (!CollectionUtils.isEmpty(recordlist)) {
//                    for (DriverPaymentsRecord driverPaymentsRecord : recordlist) {
//                        count2.setDaijiaTicheng(count2.getDaijiaTicheng().add(driverPaymentsRecord.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                    }
//                }
//            }
//        }

        long total = driverMapper.countByPage(params);
        PageVo<DirverStatistics> vopage = new PageVo<DirverStatistics>();
        vopage.setTotalElements(total);

        List<DirverStatistics> volist = new ArrayList<DirverStatistics>();
//        PageVo<DriverOrderVo> zhuanche = null;
        PageVo<DriverOrderVo> errand = null;
        PageVo<DriverOrderVo> freight = null;
        PageVo<DriverOrderVo> zhuanxian = null;

//        if (serviceSetting.isZhuanche()) {
////            zhuanche = zhuancheService.zhuancheIntroduce(companyId, start, end);
////            if (null != zhuanche) {
////                for (DriverOrderVo vo : zhuanche.getContent()) {
////                    count2.setZhuancheFinishNums(count2.getZhuancheFinishNums() + vo.getFinishNums());
////                    count2.setZhuancheMoney(count2.getZhuancheMoney().add(vo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
////                    count2.setZhuancheTicheng(count2.getZhuancheTicheng().add(vo.getTicheng()).setScale(2, BigDecimal.ROUND_HALF_UP));
////                }
////            }
//        	for (Driver driver : drivers) {
//        		PageVo<DriverOrderDetailVo> zhuanPageVo=zhuancheService.driverOrderDetail(driver.getId(), start, end);
//        		
//        		if (!CollectionUtils.isEmpty(zhuanPageVo.getContent())) {
//        			count2.setZhuancheFinishNums(zhuanPageVo.getTotalElements());
//                    for (DriverOrderDetailVo zhuanvo : zhuanPageVo.getContent()) {
//      	              	count2.setZhuancheMoney(count2.getZhuancheMoney().add(zhuanvo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
//      	              	count2.setZhuancheTicheng(count2.getZhuancheTicheng().add(zhuanvo.getTicheng()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                    }
//                }
//        	}
//        }
        if (serviceSetting.isZhuanxian()) {
            zhuanxian = zhuanxianService.zhuanxianIntroduce(companyId, start, end);
//        	if (null != zhuanxian) {
//        		for (DriverOrderVo vo : zhuanxian.getContent()) {
//        			count2.setZhuanxianFinishNums(count2.getZhuanxianFinishNums() + vo.getFinishNums());
//        			count2.setZhuanxianMoney(count2.getZhuanxianMoney().add(vo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
//        			count2.setZhuanxianTicheng(count2.getZhuanxianTicheng().add(vo.getTicheng()).setScale(2, BigDecimal.ROUND_HALF_UP));
//        		}
//        	}
        }
        if (serviceSetting.isPaotui()) {
            errand = errandService.errandIntroduce(companyId, start, end);
//            if (null != errand) {
//                for (DriverOrderVo vo : errand.getContent()) {
//                    count2.setErrandFinishNums(count2.getErrandFinishNums() + vo.getFinishNums());
//                    count2.setErrandMoney(count2.getErrandMoney().add(vo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                    count2.setErrandTicheng(count2.getErrandTicheng().add(vo.getTicheng()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                }
//            }
        }
        if (serviceSetting.isFreight()) {
            freight = freightService.freightIntroduce(companyId, start, end);
//            if (null != freight) {
//                for (DriverOrderVo vo : freight.getContent()) {
//                    count2.setFreightFinishNums(count2.getFreightFinishNums() + vo.getFinishNums());
//                    count2.setFreightMoney(count2.getFreightMoney().add(vo.getMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                    count2.setFreightTicheng(count2.getFreightTicheng().add(vo.getTicheng()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                }
//            }
        }

        DirverStatistics count = new DirverStatistics();
        count.setName("当前页总计");
        if (total > 0) {
            for (Driver driver : content) {

                Company company = companyMapper.selectByPrimaryKey(driver.getCompanyId());

                DirverStatistics dovo = new DirverStatistics();
                dovo.setDriverid(driver.getId());
                dovo.setName(driver.getRealname());
                dovo.setUsername(driver.getUsername());
                dovo.setCompanyName(company.getAbbreviation());
                dovo.setType(driver.getType());

                if (serviceSetting.isDaijia()) {
                    List<Order> orderlist = orderMapper
                        .selectFinishedByDriverWithDate(driver.getId(), start, end, null, null);

                    // 订单数 订单接
                    if (!CollectionUtils.isEmpty(orderlist)) {
                        for (Order order : orderlist) {
                            dovo.setDaijiaMoney(dovo.getDaijiaMoney().add(order.getRealCash())
                                .setScale(2, BigDecimal.ROUND_HALF_UP));
                        }
                        dovo.setDaijiaFinishNums(orderlist.size());
                    } else {
                        dovo.setDaijiaFinishNums(0);
                    }

                    // 提成
                    List<DriverPaymentsRecord> recordlist = driverPaymentsRecordMapper
                        .selectByRecordTypeAndDriver(DriverPaymentsRecord.RECHARGE_TYPE_ORDER,
                            driver.getId(), DriverPaymentsRecord.ORDER_TYPE_DAIJIA, start, end);
                    if (!CollectionUtils.isEmpty(recordlist)) {
                        for (DriverPaymentsRecord driverPaymentsRecord : recordlist) {
                            dovo.setDaijiaTicheng(
                                dovo.getDaijiaTicheng().add(driverPaymentsRecord.getMoney())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                        }
                    }

                    count.setDaijiaFinishNums(
                        count.getDaijiaFinishNums() + dovo.getDaijiaFinishNums());
                    count.setDaijiaMoney(count.getDaijiaMoney().add(dovo.getDaijiaMoney())
                        .setScale(2, BigDecimal.ROUND_HALF_UP));
                    count.setDaijiaTicheng(count.getDaijiaTicheng().add(dovo.getDaijiaTicheng())
                        .setScale(2, BigDecimal.ROUND_HALF_UP));
                }

                if (serviceSetting.isZhuanche()) {
//                    for (DriverOrderVo vo : zhuanche.getContent()) {
//                        if (vo.getDriverid().equals(dovo.getDriverid())) {
//                            dovo.setZhuancheFinishNums(vo.getFinishNums());
//                            dovo.setZhuancheTicheng(vo.getTicheng().setScale(2, BigDecimal.ROUND_HALF_UP));
//                            dovo.setZhuancheMoney(vo.getMoney().setScale(2, BigDecimal.ROUND_HALF_UP));
//                            count.setZhuancheFinishNums(count.getZhuancheFinishNums() + dovo.getZhuancheFinishNums());
//                            count.setZhuancheMoney(count.getZhuancheMoney().add(dovo.getZhuancheMoney()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                            count.setZhuancheTicheng(count.getZhuancheTicheng().add(dovo.getZhuancheTicheng()).setScale(2, BigDecimal.ROUND_HALF_UP));
//                        }
//                    }

                    PageVo<DriverOrderDetailVo> zhuanPageVo = zhuancheService
                        .driverOrderDetail2(driver.getId(), start, end);

                    // 订单数 订单接 提成
                    if (!CollectionUtils.isEmpty(zhuanPageVo.getContent())) {
                        for (DriverOrderDetailVo zhuanvo : zhuanPageVo.getContent()) {
                            dovo.setZhuancheMoney(dovo.getZhuancheMoney().add(zhuanvo.getMoney())
                                .setScale(2, BigDecimal.ROUND_HALF_UP));
                            dovo.setZhuancheTicheng(
                                dovo.getZhuancheTicheng().add(zhuanvo.getTicheng())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                        }
                        dovo.setZhuancheFinishNums(zhuanPageVo.getContent().size());
                    } else {
                        dovo.setZhuancheFinishNums(0);
                    }

                    count.setZhuancheFinishNums(
                        count.getZhuancheFinishNums() + dovo.getZhuancheFinishNums());
                    count.setZhuancheMoney(count.getZhuancheMoney().add(dovo.getZhuancheMoney())
                        .setScale(2, BigDecimal.ROUND_HALF_UP));
                    count.setZhuancheTicheng(
                        count.getZhuancheTicheng().add(dovo.getZhuancheTicheng())
                            .setScale(2, BigDecimal.ROUND_HALF_UP));
                }
                if (serviceSetting.isZhuanxian()) {
                    for (DriverOrderVo vo : zhuanxian.getContent()) {
                        if (vo.getDriverid().equals(dovo.getDriverid())) {
                            dovo.setZhuanxianFinishNums(vo.getFinishNums());
                            dovo.setZhuanxianTicheng(
                                vo.getTicheng().setScale(2, BigDecimal.ROUND_HALF_UP));
                            dovo.setZhuanxianMoney(
                                vo.getMoney().setScale(2, BigDecimal.ROUND_HALF_UP));
                            count.setZhuanxianFinishNums(
                                count.getZhuanxianFinishNums() + dovo.getZhuanxianFinishNums());
                            count.setZhuanxianMoney(
                                count.getZhuanxianMoney().add(dovo.getZhuanxianMoney())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                            count.setZhuanxianTicheng(
                                count.getZhuanxianTicheng().add(dovo.getZhuanxianTicheng())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                        }

                    }
                }

                if (serviceSetting.isPaotui()) {
                    for (DriverOrderVo vo : errand.getContent()) {
                        if (vo.getDriverid().equals(dovo.getDriverid())) {
                            dovo.setErrandFinishNums(vo.getFinishNums());
                            dovo.setErrandMoney(
                                vo.getMoney().setScale(2, BigDecimal.ROUND_HALF_UP));
                            dovo.setErrandTicheng(
                                vo.getTicheng().setScale(2, BigDecimal.ROUND_HALF_UP));
                            count.setErrandFinishNums(
                                count.getErrandFinishNums() + dovo.getErrandFinishNums());
                            count.setErrandMoney(count.getErrandMoney().add(dovo.getErrandMoney())
                                .setScale(2, BigDecimal.ROUND_HALF_UP));
                            count.setErrandTicheng(
                                count.getErrandTicheng().add(dovo.getErrandTicheng())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                        }

                    }
                }

                if (serviceSetting.isFreight()) {
                    for (DriverOrderVo vo : freight.getContent()) {
                        if (vo.getDriverid().equals(dovo.getDriverid())) {
                            dovo.setFreightFinishNums(vo.getFinishNums());
                            dovo.setFreightTicheng(
                                vo.getTicheng().setScale(2, BigDecimal.ROUND_HALF_UP));
                            dovo.setFreightMoney(
                                vo.getMoney().setScale(2, BigDecimal.ROUND_HALF_UP));
                            count.setFreightFinishNums(
                                count.getFreightFinishNums() + dovo.getFreightFinishNums());
                            count.setFreightMoney(
                                count.getFreightMoney().add(dovo.getFreightMoney())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                            count.setFreightTicheng(
                                count.getFreightTicheng().add(dovo.getFreightTicheng())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                        }

                    }
                }

                volist.add(dovo);

            }
            volist.add(count);
//            volist.add(count2);
            vopage.setContent(volist);
        } else {
            vopage.setContent(volist);
        }

        return vopage;
    }


    @Override
    public PageVo<MemberOrderVo> memberOrder(Date start, Date end, String name, Long companyId,
        Long gradeId, Integer type) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();

        StringBuilder sb = new StringBuilder();
        sb.append(passengerApi.getPassengerBaseURL() + PassengerApi.QUERY_PASSENGER
            + "?appKey={appKey}&appId={appId}&sign={sign}&page={page}&rows={rows}");

        Map<String, String> kv = new HashMap<String, String>();
        kv.put("page", String.valueOf(Pager.getPage() + 1));
        kv.put("rows", String.valueOf(Pager.getLimit()));
        if (principal.isCompanyType()) {
            if (null != companyId) {
                kv.put("companyId", String.valueOf(companyId));
                sb.append("&companyId={companyId}");
            }
        } else {
            kv.put("companyId", String.valueOf(principal.getCompanyId()));
            sb.append("&companyId={companyId}");
        }
        if (!StringUtils.isEmpty(name)) {
            kv.put("param", name);
            sb.append("&param={param}");
        }
        if (null != gradeId) {
            kv.put("gradeId", String.valueOf(gradeId));
            sb.append("&gradeId={gradeId}");
        }
        if (null != type) {
            kv.put("type", String.valueOf(type));
            sb.append("&type={type}");
        }

        String result = passengerApi.get(sb.toString(), kv, settingUtils.get());

        List<Passenger> content = new ArrayList<Passenger>();
        long total = 0;

        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");
                total = data.getLong("total");
                JSONArray ja = data.getJSONArray("rows");
                Gson gson = new Gson();
                content = gson.fromJson(ja.toString(), new TypeToken<List<Passenger>>() {
                }.getType());
            }
        }
        StringBuilder sb1 = new StringBuilder();
        sb1.append(passengerApi.getPassengerBaseURL() + PassengerApi.QUERY_PASSENGER
            + "?appKey={appKey}&appId={appId}&sign={sign}");

        Map<String, String> kv1 = new HashMap<String, String>();

        if (principal.isCompanyType()) {
            if (null != companyId) {
                kv1.put("companyId", String.valueOf(companyId));
                sb1.append("&companyId={companyId}");
            }
        } else {
            kv1.put("companyId", String.valueOf(principal.getCompanyId()));
            sb1.append("&companyId={companyId}");
        }
        if (!StringUtils.isEmpty(name)) {
            kv1.put("param", name);
            sb1.append("&param={param}");
        }
        if (null != gradeId) {
            kv1.put("gradeId", String.valueOf(gradeId));
            sb1.append("&gradeId={gradeId}");
        }
        if (null != type) {
            kv1.put("type", String.valueOf(type));
            sb1.append("&type={type}");
        }

        String result1 = passengerApi.get(sb1.toString(), kv1, settingUtils.get());

        List<Passenger> findAll = new ArrayList<Passenger>();

        if (null != result1) {
            JSONObject jo = new JSONObject(result1);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");
                total = data.getLong("total");
                JSONArray ja = data.getJSONArray("rows");
                Gson gson = new Gson();
                findAll = gson.fromJson(ja.toString(), new TypeToken<List<Passenger>>() {
                }.getType());
            }
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        PageVo<MemberOrderVo> vopage = new PageVo<MemberOrderVo>();
        List<MemberOrderVo> volist = new ArrayList<MemberOrderVo>();
        MemberOrderVo count = new MemberOrderVo();
        count.setName("总计");
        count.setPhone("");
        count.setCompanyName(" ");
        count.setMoney(BigDecimal.ZERO);

        for (Passenger passenger : findAll) {
            count.setFinishNums(count.getFinishNums() + orderMapper
                .countFinishedByMemberWithFinishTime(passenger.getId(), start, end));
            BigDecimal bigDecimal = orderMapper
                .sumMoneyByMemberWithFinishTime(passenger.getId(), start, end);
            count.setMoney(count.getMoney().add(bigDecimal != null ? bigDecimal : BigDecimal.ZERO));
        }

        MemberOrderVo count2 = new MemberOrderVo();
        count2.setName("当前页总计");
        count2.setPhone("");
        count2.setCompanyName(" ");
        count2.setMoney(BigDecimal.ZERO);

        if (!CollectionUtils.isEmpty(content)) {
            for (Passenger passenger : content) {
                MemberOrderVo mo = new MemberOrderVo();

                Company company = companyMapper.selectByPrimaryKey(passenger.getCompanyId());
                if (null != company) {
                    mo.setCompanyName(company.getAbbreviation());
                }

                mo.setName(passenger.getName());
                mo.setPhone(passenger.getPhone());

                mo.setFinishNums(
                    orderMapper.countFinishedByMemberWithFinishTime(passenger.getId(), start, end));
                mo.setMoney(
                    orderMapper.sumMoneyByMemberWithFinishTime(passenger.getId(), start, end));
                count2.setFinishNums(mo.getFinishNums() + count2.getFinishNums());
                count2.setMoney(mo.getMoney()
                    .add(count2.getMoney() != null ? count2.getMoney() : BigDecimal.ZERO));
                volist.add(mo);
            }
        }
        volist.add(count2);
        volist.add(count);
        vopage.setContent(volist);
        vopage.setTotalElements(total);

        return vopage;
    }

    @Override
    public Map<String, Object> zhuanxianCompositive(Long companyId, Long lineId, Date start,
        Date end) {

        Subject currentUser = SecurityUtils.getSubject();
        Principal principal = (Principal) currentUser.getPrincipal();
        DecimalFormat df = new DecimalFormat("######0.00");
        Long orderFinishedAmount_this;//本公司单并且是本公司司机完成单量
        Long orderBusyAmount_this;//本公司单并且是本公司司机执行中单量（包括预派单）
        Long orderFinishedAmount_getout;//本公司单并且是其他公司司机完成单量
        Long orderBusyAmount_getout;//本公司单并且是其他公司司机执行中单量（包括预派单）
        Long orderCanceledAmount;//本公司订单销单量
        Long orderFinishedAmount_comein;//其他公司单并且是本公司司机完成单量
        Long orderBusyAmount_comein;//其他公司单并且是本公司司机执行中单量（包括预派单）
        Long orderTotalAmount = 0L;//总单量

        Double orderTotalCouponMoney = 0d;
        Double totalGuoluMoney = 0d;//过路费
        Double orderFinishedCouponMoney_this = 0d;//由本公司司机完成订单优惠券金额;
        Double orderFinishedCouponMoney_getout = 0d;//由平台其它公司司机完成订单优惠券金额;
        Double orderFinishedCouponMoney_comein = 0d;//平台其它公司创建、由本公司司机完成的订单优惠券金额;

        Double orderFinishedMoney_this = 0d;
        Double orderFinishedMoney_getout = 0d;
        Double orderFinishedMoney_comein = 0d;
        Double orderTotalMoney = 0d;

        Double orderFinishedCompanyMoney_this = 0d;
        Double orderFinishedCompanyMoney_getout = 0d;
        Double orderFinishedCompanyMoney_comein = 0d;
        Double orderTotalCompanyMoney = 0d;

        Double orderFinishedDriverMoney_this = 0d;
        Double orderFinishedDriverMoney_getout = 0d;
        Double orderFinishedDriverMoney_comein = 0d;
        Double orderTotalDriverMoney = 0d;

        Map<String, Object> map = new HashMap<String, Object>();

        StringBuilder sb = new StringBuilder();
        sb.append(
            zhuanxianApi.getZhuanxianBaseURL() + ZhuanxianApi.COMPOSITIVE + "?appKey={appKey}");

        Map<String, String> kv = new HashMap<String, String>();

        kv.put("companyId", String.valueOf(companyId));
        sb.append("&companyId={companyId}");

        if (null != start) {
            kv.put("start", String.valueOf(start.getTime()));
            sb.append("&start={start}");
        }
        if (null != end) {
            kv.put("end", String.valueOf(end.getTime()));
            sb.append("&end={end}");
        }
        if (lineId != null) {
            kv.put("lineId", String.valueOf(lineId));
            sb.append("&lineId={lineId}");
        }
        if (principal.isCompanyType()) {
            kv.put("maincompany", Boolean.TRUE.toString());
            sb.append("&maincompany={maincompany}");
        } else {
            kv.put("maincompany", Boolean.FALSE.toString());
            sb.append("&maincompany={maincompany}");
        }

        String result = zhuanxianApi.get(sb.toString(), kv, settingUtils.get());
        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");

                orderFinishedAmount_this = data.getLong("orderNumber");
                orderBusyAmount_this = data.getLong("runOrderNumber");
                orderFinishedAmount_getout = data.getLong("otherOrderNumber");
                orderBusyAmount_getout = data.getLong("runOtherOrderNumber");
                orderCanceledAmount = data.getLong("cancelOrderNumber");
                orderFinishedAmount_comein = data.getLong("inOrderNumber");
                orderBusyAmount_comein = data.getLong("inRunOrderNumber");
                orderTotalAmount = data.getLong("sumOrderNumber");
                map.put("orderFinishedAmount_this", orderFinishedAmount_this);
                map.put("orderBusyAmount_this", orderBusyAmount_this);
                map.put("orderFinishedAmount_getout", orderFinishedAmount_getout);
                map.put("orderBusyAmount_getout", orderBusyAmount_getout);
                map.put("orderCanceledAmount", orderCanceledAmount);
                map.put("orderFinishedAmount_comein", orderFinishedAmount_comein);
                map.put("orderBusyAmount_comein", orderBusyAmount_comein);
                map.put("orderTotalAmount", orderTotalAmount);

                orderFinishedMoney_this = data.getDouble("orderRealCash");
                orderFinishedMoney_getout = data.getDouble("otherOrderRealCash");
                orderFinishedMoney_comein = data.getDouble("inOrderRealCash");
                orderTotalMoney = data.getDouble("sumOrderRealCash");
                map.put("orderFinishedMoney_this",
                    new BigDecimal(orderFinishedMoney_this).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedMoney_getout",
                    new BigDecimal(orderFinishedMoney_getout).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedMoney_comein",
                    new BigDecimal(orderFinishedMoney_comein).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderTotalMoney",
                    new BigDecimal(orderTotalMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderFinishedCompanyMoney_this = data.getDouble("companyProfit");
                orderFinishedCompanyMoney_getout = data.getDouble("otherCompanyProfit");
                orderFinishedCompanyMoney_comein = data.getDouble("inCompanyProfit");
                orderTotalCompanyMoney = data.getDouble("sumCompanyProfit");
                map.put("orderFinishedCompanyMoney_this",
                    new BigDecimal(orderFinishedCompanyMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCompanyMoney_getout",
                    new BigDecimal(orderFinishedCompanyMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCompanyMoney_comein",
                    new BigDecimal(orderFinishedCompanyMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalCompanyMoney",
                    new BigDecimal(orderTotalCompanyMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderFinishedDriverMoney_this = data.getDouble("driverProfit");
                orderFinishedDriverMoney_getout = data.getDouble("otherDriverProfit");
                orderFinishedDriverMoney_comein = data.getDouble("inDriverProfit");
                orderTotalDriverMoney = data.getDouble("sumDriverProfit");
                map.put("orderFinishedDriverMoney_this",
                    new BigDecimal(orderFinishedDriverMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedDriverMoney_getout",
                    new BigDecimal(orderFinishedDriverMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedDriverMoney_comein",
                    new BigDecimal(orderFinishedDriverMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderTotalDriverMoney",
                    new BigDecimal(orderTotalDriverMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());

                orderTotalCouponMoney = data.getDouble("orderTotalCouponMoney");
                orderFinishedCouponMoney_this = data.getDouble("orderFinishedCouponMoney_this");
                orderFinishedCouponMoney_getout = data.getDouble("orderFinishedCouponMoney_getout");
                orderFinishedCouponMoney_comein = data.getDouble("orderFinishedCouponMoney_comein");
                map.put("orderTotalCouponMoney",
                    new BigDecimal(orderTotalCouponMoney).setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                map.put("orderFinishedCouponMoney_this",
                    new BigDecimal(orderFinishedCouponMoney_this)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCouponMoney_getout",
                    new BigDecimal(orderFinishedCouponMoney_getout)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                map.put("orderFinishedCouponMoney_comein",
                    new BigDecimal(orderFinishedCouponMoney_comein)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                if (principal.isCompanyType()) {
                    map.put("totalAmount", new BigDecimal(data.getDouble("totalAmount"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalGuoluMoney", new BigDecimal(data.getDouble("totalGuoluMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCancelAmount", new BigDecimal(data.getDouble("totalCancelAmount"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalRealCash", new BigDecimal(data.getDouble("totalRealCash"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalPayMoney", new BigDecimal(data.getDouble("totalPayMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCompanyMoney",
                        new BigDecimal(data.getDouble("totalCompanyProfit"))
                            .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalDriverMoney", new BigDecimal(data.getDouble("totalDriverProfit"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                    map.put("totalCouponMoney", new BigDecimal(data.getDouble("totalCouponMoney"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                }

            }
        }

        return map;
    }

    @Override
    public PageVo<DriverOrderDetailVo> driverOrderDetailCount(Long driverId, Date start, Date end) {
        PageVo<DriverOrderDetailVo> vopage = new PageVo<DriverOrderDetailVo>();
        long totalElements = orderMapper.countFinishedByDriverWithDate(driverId, start, end);
        vopage.setTotalElements(totalElements);
        return vopage;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateByPrimaryKey(ChartYear chartYear) {

        chartYearMapper.updateByPrimaryKey(chartYear);
    }


}
